devour-client icon indicating copy to clipboard operation
devour-client copied to clipboard

Receiving: undefined is not an object (evaluating 'source.pointer')

Open erkde opened this issue 8 years ago • 0 comments

I'm trying to have devour (v2.0.7) receive following response in an RN app:

{
  "errors":[
    {
      "title":"Authentication failed",
      "detail":"Invalid username and/or password",
      "code":"101",
      "status":"400"
    }
  ]
}

but, I'm seeing the following error:

undefined is not an object (evaluating 'source.pointer')
- node_modules/devour-client/lib/middleware/json-api/res-errors.js:46:13 in errorKey
- node_modules/devour-client/lib/middleware/json-api/res-errors.js:24:24 in buildErrors
- ... 10 more stack frames from framework internals

I'm new to JSON API, so looking at the docs (http://jsonapi.org/format/#error-objects) I noticed it said an error object MAY have one or more attributes, instead of MUST as used elsewhere. So just wondering if this is still correct?

Otherwise, looking at that code, maybe it's worth checking if source is present as well?

function errorKey(index, source) {
  if (!source || source.pointer == null) {
    return index;
  }
  return source.pointer.split('/').pop();
}

Env

Devour 2.0.7 RN 0.50.3

erkde avatar Dec 08 '17 08:12 erkde