Skip to content

Batching - unable to get .json() to work on json response #204

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

Closed
4 tasks done
nmetulev opened this issue Jul 23, 2019 · 0 comments · Fixed by #213
Closed
4 tasks done

Batching - unable to get .json() to work on json response #204

nmetulev opened this issue Jul 23, 2019 · 0 comments · Fixed by #213
Assignees

Comments

@nmetulev
Copy link
Contributor

nmetulev commented Jul 23, 2019

Bug Report

Prerequisites

  • Can you reproduce the problem?
  • Are you running the latest version?
  • Are you reporting to the correct repository?
  • Did you perform a cursory search?

Description

I'm attempting to use the batching api to get a response for both the /me and the /me/photo/$value endpoint. However, using the .json() method on the me response throws an exception. In contrast, the .blob() on the photo response works. Alternatively, I've been able to get the json of me by going directly to the body of the response, which is no different that making the fetch response myself.

Console Errors: [Is there any console error]

Uncaught (in promise) SyntaxError: Unexpected token o in JSON at position 1

Steps to Reproduce

    let photoRequest = new Request('/me/photo/$value', {
      method: 'GET'
    });

    let meRequest = new Request('/me', {
      method: 'GET'
    });

    let batchRequestContent = new BatchRequestContent([
      {
        request: photoRequest,
        id: '1'
      },
      {
        request: meRequest,
        id: '2'
      }
    ]);

    let content = await batchRequestContent.getContent();

    let response = await this.client
      .api('$batch')
      .post(content);

    let batchResponse = new BatchResponseContent(response);
    let responses = batchResponse.getResponses();
    
    // this works
    let blob = await responses.get('1').blob();

    // this throws exception
    // Uncaught (in promise) SyntaxError: Unexpected token o in JSON at position 1
    let me = await responses.get('2').json();

    // alternative that works
    let me = response.responses[0].body

Expected behavior: [What you expected to happen]
I expect .json() to work or have documentation for the recommended way to access the response json

Actual behavior: [What actually happened]
.json() throws an exception

Additional context

I've found the batching docs are missing the final example of how to retrieve the content of each request.

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

Successfully merging a pull request may close this issue.

2 participants