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

Should we always need to response a document for addRecord? #943

Open
towerhe opened this issue Mar 26, 2022 · 1 comment
Open

Should we always need to response a document for addRecord? #943

towerhe opened this issue Mar 26, 2022 · 1 comment
Labels

Comments

@towerhe
Copy link

towerhe commented Mar 26, 2022

As described in the JSONAPI spec:

7.1.2.3 204 No Content

If a POST request did include a Client-Generated ID and the requested resource has been created successfully, the server MUST return either a 201 Created status code and response document (as described above) or a 204 No Content status code with no response document.

I have APIs response 204. When I try to create my resources with addRecord, I got the following errors:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'data')
    at JSONAPIDocumentSerializer.deserialize

I checked through the codes of orbit.js, and I found the TransformRequestProcessors.addRecord() always needs a document in the response.

    const url =
      request.options?.url ??
      requestProcessor.urlBuilder.resourceURL(record.type);

    const details = await requestProcessor.fetch(url, settings);
    const document = details.document as ResourceDocument;
    requestProcessor.preprocessResponseDocument(document, request);

Is there a way to fulfill my requirements?

@dgeb
Copy link
Member

dgeb commented Apr 2, 2022

@towerhe you're correct that a 204 is a valid response. I'll mark this as a bug and address it soon.

@dgeb dgeb added the bug label Apr 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants