Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PATCH Save does not support response 200 with content null #302

Open
youngSocke opened this issue Feb 24, 2021 · 0 comments
Open

PATCH Save does not support response 200 with content null #302

youngSocke opened this issue Feb 24, 2021 · 0 comments

Comments

@youngSocke
Copy link

According to the specification the server is allowed to send no data but when I try to save a resource with an id which results in a patch request the following error occurs while processing the response.

My code:
this.resource.save().subscribe(() => { console.log('success'); });

Error
core.js:6157 ERROR TypeError: Cannot read property 'data' of null at SafeSubscriber.Core.exec.subscribe.is_saving [as _next] (ngx-jsonapi.js:915)

JSON:API - Latest Specification (v1.0)

Updating Resources: A server MUST return a 200 OK status code if an update is successful, the client’s current fields remain up to date, and the server responds only with top-level meta data. In this case the server MUST NOT include a representation of the updated resource(s).

In my opinion the problem relies in the following code snippet where there is a null check missing to make it work when no content is returned from the server.
Before:
if ('id' in success.data) { this.id = success.data.id; this.fill(/** @type {?} */ (success)); } else if (Array.isArray(success.data)) { console.warn('Server return a collection when we save()', success.data); }

After:
if (!!success && 'id' in success.data) { this.id = success.data.id; this.fill(/** @type {?} */ (success)); } else if (!!success && Array.isArray(success.data)) { console.warn('Server return a collection when we save()', success.data); }

I would appreciate it very much if you could look into this issue and maybe provide a fix soon.
Best regards!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant