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

[RFC] Better error messaging for GraphQuery #209

Closed
phillysnow opened this issue Jan 20, 2022 · 6 comments
Closed

[RFC] Better error messaging for GraphQuery #209

phillysnow opened this issue Jan 20, 2022 · 6 comments
Labels
enhancement New feature or request

Comments

@phillysnow
Copy link
Contributor

Issue

When users currently do not correctly format a GraphQuery their queries simply fail.

Solution

The API browser for example returns more specific error messaging:

  <body>
  
      <p>Unable to parse fetch query Invalid fetch parsing Exception.

A composite slice can only contains `primary` or `repeat` or both.</p>
    
  </body>

Could we pull this error messaging into the Client?

Forum

https://community.prismic.io/t/not-able-to-query-slice-machine-slices-with-graphquery/7030/24

@phillysnow phillysnow added the enhancement New feature or request label Jan 20, 2022
@phillysnow
Copy link
Contributor Author

Oh lord, that's nice.

@angeloashmore
Copy link
Member

Hey @phillysnow, the v6 client handles this by returning a ParsingError. The helpfulness of the error is limited by the API response ("A composite slice can only contains primary or repeat or both" isn't exactly the most helpful message).

When making the same query as linked in the issue and above, the client will throw the following error (graphQuery is the linked GraphQuery string saved in a variable). It is the same error displayed by the API browser.

> client.getByUID('page', 'contact-us', { graphQuery }).then(x => console.log(x)).catch(x => console.log(x))
> ParsingError: Unable to parse fetch query Invalid fetch parsing Exception.

A composite slice can only contains `primary` or `repeat` or both.
    at Client.fetch (/Users/angeloashmore/projects/prismic/prismic-client/dist/index.cjs:524:15)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async Client.getFirst (/Users/angeloashmore/projects/prismic/prismic-client/dist/index.cjs:264:20)
    at async Client.getByUID (/Users/angeloashmore/projects/prismic/prismic-client/dist/index.cjs:299:12) {
  url: 'https://smallbydesign.cdn.prismic.io/api/v2/documents/search?q=%5B%5Bat%28document.type%2C+%22page%22%29%5D%5D&q=%5B%5Bat%28my.page.uid%2C+%22contact-us%22%29%5D%5D&graphQuery=%7B%0Apage%7B%0A...pageFields%0Aslices%7B%0A...onform_section%7B%0Avariation%7B%0A...ondefault-slice%7B%0Aprimary%7B%0AformLink%7B%0A...onform%7B%0Aslices%7B%0A...onform_input%7B%0Avariation%7B%0A...ondefault-slice%7B%0Arepeat%7B%0A...primaryFields%0A%7D%0A%7D%0A%7D%0A%7D%0A%7D%0A%7D%0A%7D%0A%7D%0A%7D%0A%7D%0A%7D%0A%7D%0A%7D%0A%7D&ref=YedLOREAACoA6f28',
  response: {
    type: 'api_validation_error',
    message: 'Unable to parse fetch query Invalid fetch parsing Exception.\n' +
      '\n' +
      'A composite slice can only contains `primary` or `repeat` or both.'
  }
}

Related, but just a side note that non-CDN version returns HTML, while CDN version returns JSON (same content though)

Huh, interesting! That seems like an API issue rather than something that should be handled in the client. What do you think @lihbr?

@phillysnow
Copy link
Contributor Author

OK, so the client already returns this info, that's awesome. I agree, we could definitely speak with the dev team about making these error messages more helpful though.

@lihbr
Copy link
Member

lihbr commented Jan 21, 2022

Huh, interesting! That seems like an API issue rather than something that should be handled in the client. What do you think @lihbr?

OK, actually the non-CDN version returns HTML because accessed from a browser (user-agent based?) using tools like Insomnia it returns valid JSON. Definitely shouldn't be handled by the client.

@angeloashmore
Copy link
Member

I'm going to close this since the client already handles this by throwing a ParsingError. If anyone has suggestions on improving this (considering the API limitations), please feel free to share. 🙂

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

No branches or pull requests

3 participants