on-internet
← Community

How can I handle GraphQL error status codes and pass them from the backend to the frontend in an Express app?

Stack Overflow ·

I am building a full-stack application using React on the frontend and Express with GraphQL on the backend. I need to handle errors in my GraphQL mutation and pass the appropriate status codes (like 409 for conflicts, 422 for validation errors, etc.) from the backend to the frontend. However, when an error occurs in the GraphQL mutation, I am unable to pass the correct HTTP status code to the frontend. Here's what I have so far: Backend (Express + GraphQL) I am using graphql-http to set up the GraphQL handler in my Express app, and I use formatError to catch GraphQL errors. Here’s how I set up

Comments

Sign in or sign up to comment and upvote.

No comments yet.