Skip to content

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

Open

Description

@towerhe

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?

Activity

  1. dgeb commented on Apr 2, 2022

    @dgeb
    Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions