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

How to respond with a server error? #68

Open
tniezurawski opened this issue Mar 29, 2023 · 3 comments
Open

How to respond with a server error? #68

tniezurawski opened this issue Mar 29, 2023 · 3 comments

Comments

@tniezurawski
Copy link

tniezurawski commented Mar 29, 2023

Hey folks 👋 I'm struggling with responding with a server error. I use the typical mirage way. Say, I want to simulate 502s and test Apollo's retry mechanism, so under some fake conditions I return this for a query:

return new Response(502);

But what I get returned instead is wrapped in GraphQL error. It looks like miragejs/graphql (or something internally) treats my response with 502 as a regular response and complains that the data is not returned properly:

image

Is it possible that miragejs/graphql is not aware that it should "re-throw" (pass) the error? Could someone give me pointers on where I should look to fill the gap?

@jneurock
Copy link
Collaborator

This is due to how GraphQL itself works. If the GraphQL endpoint is reachable, it wraps errors and includes them in the response. You won’t be able to simulate a 5xx type error by throwing one while resolving a query.

You should be able to override the route handler for the GraphQL endpoint where needed, though:

// Assumes `server` is the instance of the Mirage server
server.post('<path-to-graphql>', new Response(502))

@tniezurawski
Copy link
Author

@jneurock Uh, that would be quite global, right?

@jneurock
Copy link
Collaborator

It depends on how you’re using Mirage. I thought you mentioned testing and, if you’re using Mirage in a testing context, defining a route handler in a test is not global.

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

No branches or pull requests

2 participants