Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix changeset errors #262

Merged
merged 2 commits into from Apr 17, 2023
Merged

Conversation

kelostrada
Copy link
Contributor

This fixes error handing, example:

image

There are two changes. First of all we had an issue that this was not working at all and throwing like this:

(CaseClauseError no case clause matching: {:error, {:error, #Ecto.Changeset<action: :update, changes: %{is_admin: "**redacted**"}, errors: [is_admin: {"cannot set is_admin for non official emails", []}], data: #Api.Accounts.User<>, valid?: false>}})

This happens because the error handling in lib/kaffy/resource_callbacks.ex wraps the "unexpected" errors in the error tuple, which is pointless when the error is already an error tuple. For example this results in {:error, {:error, Ecto.Changeset.t()}} tuple which can't be then handled correctly.

Second after I fixed this I noticed the errors are not displayed in details so this was the second part of the fix. You can notice I added a simple helper function - add_class/2 which basically appends the class in the opts instead of overwriting it every time. We have even places where we put the new class one after another which makes the old value redundant.

@ghenry
Copy link
Collaborator

ghenry commented Apr 17, 2023

Thanks for taking the time to submit this PR! Very kind of you.

@ghenry ghenry merged commit 68a0875 into aesmail:master Apr 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants