Data: Adapter error while parsing JSONApi errors

Created on 27 Dec 2019  ยท  12Comments  ยท  Source: emberjs/data

Thank you for opening this issue!

Hi ember-data team,

Thanks a lot for the great word that you made to bring ember octane alive. It's so cool.

I've got a strange error while using that new version of ember into a new project: I can't get the JSON API error parsing working correctly. Despite I'm generating valid error messages, ember is keeping generating adapter errors.

Reproduction

To reproduce the issue, I've created a mini-project, consisting of a very simple server, only producing JSONAPI error objects, and a simple frontend, with a single action.

To use it:

Clone my repository
https://github.com/aclarembeau/ember-issue-demo/tree/master

Run the express server in back/ , run the ember project in front/.

Then, open a browser, click on the link, this will open a debugger session.
Dump the value of the "e" variable, you'll see that it's an AdapterError, resulting from an incorrect parsing of the JSONAPI error returned by the server.

Description

I've investigated a bit, and it seems that the issue comes from the following file:
https://github.com/emberjs/data/blob/cf153484fd4077eea56ea877c4fac2acaa94fcee/packages/adapter/addon/rest.js

In the definition of the function
handleResponse(status, headers, payload, requestData) {

You're doing return new InvalidError(payload.errors);

However, after investigating a bit, it seems that "payload" is not a javascript object, but a string. So, if I add a JSON.parse instruction before that call, everything works well.

I don't know exactly where should that JSON.parse call go exactly in the code, since, all from the beginning of the ajax respose, payload is always a string (and never a javascript object), so, I'm not feeling confident making a PR to solve this. So, if someone can have a look, this would be really great.

Versions

yarn list v1.15.2
warning Filtering by arguments is deprecated. Please use the pattern option instead.
โ””โ”€ [email protected]
โœจ  Done in 0.99s.
yarn list v1.15.2
warning Filtering by arguments is deprecated. Please use the pattern option instead.
โ””โ”€ [email protected]
โœจ  Done in 0.79s.
yarn list v1.15.2
โ”œโ”€ @ember-data/[email protected]
โ”œโ”€ @ember-data/[email protected]
โ”œโ”€ @ember-data/[email protected]
โ”œโ”€ @ember-data/[email protected]
โ”œโ”€ @ember-data/[email protected]
โ”œโ”€ @ember-data/[email protected]
โ”œโ”€ @ember-data/[email protected]
โ”œโ”€ @ember-data/[email protected]
โ”œโ”€ @ember-data/[email protected]
โ””โ”€ [email protected]

Most helpful comment

I'm seeing this as well, when jquery-integration is disabled, Octane or no, on 3.15.

All 12 comments

I'm seeing this as well, when jquery-integration is disabled, Octane or no, on 3.15.

I've made a PR to solve this: https://github.com/emberjs/data/pull/6941

I'm experiencing this same issue on my site. Just upgraded to 3.15.1 and now my error responses are not being handled properly.

This method has a JSDoc that states:

"Function that always attempts to parse the response as json, and if an error is thrown"

However, if the response does not return successful it returns the payload without parsing it to JSON first. This seems to be a bug based on the JSDoc.

@kkincade what version were you upgrading from?

@hjdivad I am seeing non-parsed JSON-api errors after upgrading from 3.14 to 3.15.1. I had to turn query integration on to fix the issue.

I think I'm experiencing the same issue. Suddenly all usage of model.errors (https://api.emberjs.com/ember-data/3.16/classes/Model/properties/errors?anchor=errors) stopped working in our app when we updated to ED 3.15.

@runspired was the fix released in 3.15.x or 3.16.x?

@andreyfel neither, but it will get back ported to 3.16 and 3.17 beta

@runspired have this one missed back port ? I would love to upgrade to 3.16 ๐Ÿ‘

Is there any ETA for this to land in 3.16? IMO it is a severe bug which contradicts with documented ED features and it is frustrating that the latest release has this issue while the fix is merged to master 22 days ago.

Cc @HeroicEric and @igorT for release

I'm following up with @HeroicEric and will try to get a release out soon

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kennethlarsen picture kennethlarsen  ยท  3Comments

HenryVonfire picture HenryVonfire  ยท  3Comments

bartocc picture bartocc  ยท  4Comments

jcano picture jcano  ยท  4Comments

toobulkeh picture toobulkeh  ยท  3Comments