Error handling
See original GitHub issueRelated to #13, I’m going to fork this library to add in proper error object support in order to conform with JSON API’s standards on throwing errors.
Anything in particular I should be aware of/attempt to implement while I’m at it?
I’m not planning on parsing error codes and such within jsonapi-serializer - just properly handling a supplied error object. My biggest question is whether I should add an err
(like JSONAPISerializer(type, data, opts, err)
) or magically parse a supplied error
type, or include it in opts
ala meta
, or something else? (Could also add a JSONAPISerializer.error(type, data, opts)
).
I know part of the goal with jsonapi-serializer is to be as agnostic as possible and I plan on submitting a PR when I’m done so any thoughts on best practices as I work on this would be appreciated. 😃
Issue Analytics
- State:
- Created 8 years ago
- Reactions:2
- Comments:7 (2 by maintainers)
Any updates here?
Since per jsonapi standards, you cannot have a response with both a “data” and “errors” object, I decided to magically treat any supplied “error” or “errors” collection/resource as an error and parse it from there, so you can just
JSONApiSerializer('error', errorData, opts)
and it will spit out the appropriate response.I haven’t finished implementing all the
opts
yet (onlymeta
andtopLevelLinks
– I’m currently just doingpayload.errors.push(records)
instead of something likeErrorSerliazerUtils()
.) When I get that done, I’ll do a PR, but it might be a few more days because we actually don’t need any of the other options. https://github.com/brettneese/jsonapi-serializer