question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature] Set custom error object in rtk-query/graphql-request-base-query

See original GitHub issue

Proposal Feature: graphqlRequestBaseQuery shoud give the option to set the error response object, using the graphql response

Possible example:

export const api = createApi({
  baseQuery: graphqlRequestBaseQuery({
    client,
    customErrors: ({ name, message, request, stack, response }) => {
      return {
        name,
        stack,
        message: response?.errors[0]?.extensions?.errorMessage,
        errorCode: response?.errors[0]?.extensions?.errorCode
      };
    }
  }),
  endpoints: () => ({}),
  refetchOnMountOrArgChange: true
});

In the example the customError callback provides the error returned from the graphql-response client

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:3
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
phryneascommented, Jun 10, 2022

My plan was to spend the day on PRs, so I’m getting to this one next 😃

1reaction
phryneascommented, Apr 22, 2022

Yeah, I’m very sorry - I mean I suggested you do this PR in the first place. Unfortunately I’m pretty much behind on everything right now. I’ll try to get to it soon, but it’s probably going to be end of next week.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error handling - Apollo GraphQL Docs
When Apollo Server formats an error in a response, it sets the code extension to this value if no other code is set....
Read more >
Custom errors, extending Error - The Modern JavaScript Tutorial
The parent constructor sets the message property. ... Here's the code with MyError and other custom error classes, simplified:.
Read more >
Set a Custom Error Message That Returns as an Object
A Custom Error Message returns based on a defined path and value. Set custom error messages for File elements, Image elements, all Action...
Read more >
Creating Custom Errors in Go - DigitalOcean
In this example, we create a new instance of RequestError and provide the status code and an error using the errors.New function from...
Read more >
Error - JavaScript - MDN Web Docs - Mozilla
The Error object can also be used as a base object for user-defined ... Note: Some browsers include the CustomError constructor in the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found