I have an 500 error when my user changes UUID which is relation to Category UUID for inserting post.
** (exit) an exception was raised:
** (Ecto.ChangeError) value `"a863228-727c-4cf3-93f5-9b2f79df1288"` for `TrangellCmsService.Cms.Db.Post.cms_post_category_id` in `insert` does not match type :binary_id
How do I prevent an 500 error in client request? I want to show 400 error instead of 500 error , how do ?
my changeset :
def changeset(struct, params \\ %{}) do
struct
|> cast(params, @all_fields)
|> validate_required(@all_fields)
|> unique_constraint(:seo_alias_link, name: :index_of_post_alias_unique_link, message: "alias link already exists.")
|> validate_inclusion(:seo_language, ["en", "fa"])
|> validate_inclusion(:group_acl, ["admin", "actived", "unactived", "blocked"])
|> validate_inclusion(:post_type, ["article", "shop", "free"])
|> validate_length(:title, min: 3, max: 100)
|> validate_length(:description, min: 100)
|> validate_length(:seo_words, min: 3, max: 100)
|> validate_length(:seo_description, min: 50, max: 264)
|> foreign_key_constraint(:cms_post_category_id)
end