vt-elixir / ja_resource

A behaviour to reduce boilerplate code in your JSON-API compliant Phoenix controllers without sacrificing flexibility.
Other
113 stars 33 forks source link

Error when trying to render errors #68

Closed nathanl closed 4 years ago

nathanl commented 7 years ago

The docs for v0.3.0 show returning an error like this from handle_update:

{:error, author_id: "you can only edit your own posts"}

If I do that, I get an error from ja_serializer (I'm using 0.12.0):

 ** (BadMapError) expected a map, got: {:author_id, "you can only edit your own posts"}

From digging in its source, I figured out that I could successfully render errors formatted like:

{:error, [%{title: "something", detail: "something else"}]}

Are the docs wrong? If not, what am I doing wrong?

psteininger commented 4 years ago

@nathanl I know this is 2.5 years too late, but it appears that handle_update/3 returns whatever __MODULE__.model.changeset(model, attributes) returns. So just follow whatever Ecto is using, which is the last example in the issue.