SeyZ / jsonapi-serializer

A Node.js framework agnostic library for (de)serializing your data to JSON API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error Deserialization

sepowitz opened this issue · comments

Hey there,

Really liking the lib, but curious why the deserializer doesn't handle json api complicant error messages, and how we should approach error deserialization using this lib.

I am attempting to deserialize a json api error:
Error example:

{
  "errors":[
    {"detail":"Shipping address is invalid","source": 
    {"pointer":"/data/attributes/shipping_address"},"title":"is invalid"}
  ],
"jsonapi":{"version":"1.0"}
}

But am getting a type error, because attributes cannot be found:

TypeError: Cannot read property 'attributes' of undefined
    at extractAttributes (deserializer-utils.js:96)
    at push../node_modules/jsonapi-serializer/lib/deserializer-utils.js.module.exports.perform (deserializer-utils.js:161)
    at resource (deserializer.js:26)
    at deserialize (deserializer.js:38)
    at index.js:51

Any help would be greatly appreciated.

I am deserializing the following JSON and am getting the same error.

{
	"data": {
	   "type": "SomeModelType",
	    "attributes": {
	      "name": "Some Custom Option",
               "value": "This is the Value"
	     }
         }
}

Error Message

Debug: handler, error
    TypeError: Cannot read property 'attributes' of undefined
    at extractAttributes (.../node_modules/jsonapi-serializer/lib/deserializer-utils.js:89:37)
    at module.exports.perform (.../node_modules/jsonapi-serializer/lib/deserializer-utils.js:149:13)
    at resource (.../node_modules/jsonapi-serializer/lib/deserializer.js:25:10)