[Feature] Set custom error object in rtk-query/graphql-request-base-query
See original GitHub issueProposal 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:
- Created a year ago
- Reactions:3
- Comments:7 (6 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
My plan was to spend the day on PRs, so I’m getting to this one next 😃
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.