Error thrown in Resolver always results in a 500 Status code
See original GitHub issueI have this resolver setup
export const authRouter = createRouter().mutation("login", {
input: LoginInput,
async resolve({ input, ctx }) {
throw trpc.httpError.unauthorized("Optional message");
},
});
Which should result in a 401 status code, however, the error that is actually sent by the endpoint is (with a 500 code):
TRPCError: Optional message
at internalServerError (C:\Users\malte\Github\streamparty\monorepo\packages\website-next\.next\server\pages\api\v2\trpc\[trpc].js:264:10)
at getErrorFromUnknown (C:\Users\malte\Github\streamparty\monorepo\packages\website-next\.next\server\pages\api\v2\trpc\[trpc].js:289:10)
at Object.requestHandler (C:\Users\malte\Github\streamparty\monorepo\packages\website-next\.next\server\pages\api\v2\trpc\[trpc].js:558:19)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:94:5)
at async C:\Users\malte\Github\streamparty\monorepo\packages\website-next\.next\server\pages\api\v2\trpc\[trpc].js:184:5
at async apiResolver (C:\Users\malte\Github\streamparty\monorepo\packages\website-next\node_modules\next\dist\next-server\server\api-utils.js:8:1)
at async DevServer.handleApiRequest (C:\Users\malte\Github\streamparty\monorepo\packages\website-next\node_modules\next\dist\next-server\server\next-server.js:67:462)
at async Object.fn (C:\Users\malte\Github\streamparty\monorepo\packages\website-next\node_modules\next\dist\next-server\server\next-server.js:59:492)
at async Router.execute (C:\Users\malte\Github\streamparty\monorepo\packages\website-next\node_modules\next\dist\next-server\server\router.js:25:67)
at async DevServer.run (C:\Users\malte\Github\streamparty\monorepo\packages\website-next\node_modules\next\dist\next-server\server\next-server.js:69:1042)
at async DevServer.handleRequest (C:\Users\malte\Github\streamparty\monorepo\packages\website-next\node_modules\next\dist\next-server\server\next-server.js:34:504) {
originalError: HTTPError: Optional message
at Object.unauthorized (C:\Users\malte\Github\streamparty\monorepo\node_modules\@trpc\server\dist\http-c0b986e9.cjs.dev.js:98:28)
at ProcedureWithInput.resolve [as resolver] (C:\Users\malte\Github\streamparty\monorepo\packages\website-next\.next\server\pages\api\v2\trpc\[trpc].js:1381:66)
at ProcedureWithInput.call (C:\Users\malte\Github\streamparty\monorepo\node_modules\@trpc\server\dist\router-91b6d32c.cjs.dev.js:61:31)
at Router.invoke (C:\Users\malte\Github\streamparty\monorepo\node_modules\@trpc\server\dist\router-91b6d32c.cjs.dev.js:266:22)
at Object.mutation (C:\Users\malte\Github\streamparty\monorepo\node_modules\@trpc\server\dist\router-91b6d32c.cjs.dev.js:285:21)
at Object.requestHandler (C:\Users\malte\Github\streamparty\monorepo\packages\website-next\.next\server\pages\api\v2\trpc\[trpc].js:460:29)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:94:5)
at async C:\Users\malte\Github\streamparty\monorepo\packages\website-next\.next\server\pages\api\v2\trpc\[trpc].js:184:5
at async apiResolver (C:\Users\malte\Github\streamparty\monorepo\packages\website-next\node_modules\next\dist\next-server\server\api-utils.js:8:1)
at async DevServer.handleApiRequest (C:\Users\malte\Github\streamparty\monorepo\packages\website-next\node_modules\next\dist\next-server\server\next-server.js:67:462)
at async Object.fn (C:\Users\malte\Github\streamparty\monorepo\packages\website-next\node_modules\next\dist\next-server\server\next-server.js:59:492)
at async Router.execute (C:\Users\malte\Github\streamparty\monorepo\packages\website-next\node_modules\next\dist\next-server\server\router.js:25:67)
at async DevServer.run (C:\Users\malte\Github\streamparty\monorepo\packages\website-next\node_modules\next\dist\next-server\server\next-server.js:69:1042)
at async DevServer.handleRequest (C:\Users\malte\Github\streamparty\monorepo\packages\website-next\node_modules\next\dist\next-server\server\next-server.js:34:504) {
originalError: undefined,
code: 'UNAUTHENTICATED',
statusCode: 401
},
code: 'INTERNAL_SERVER_ERROR'
}
Should this be the case? Let me know if you need any extra information
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:10 (7 by maintainers)
Top Results From Across the Web
Error handling - Apollo GraphQL Docs
If Apollo Server hasn't correctly started up or is in the process of shutting down, it responds with a 500 status code. The...
Read more >express graphql always sends 500 Internal server error for ...
The express-graphql sends the HTTP error 500 whenever detects there is no data returned. Definitely, in case of exception is thrown there ...
Read more >How to Fix a 500 Internal Server Error 🛠️
The 500 Internal Server Error status code occurs when the server encounters an error that prevents it from fulfilling the request.
Read more >Queries returning only errors are forced to be a 500 #427
+1 having an issue doing proper error handling in client-side as it always returns status 500 if the response must be non null....
Read more >What Is a "500 Internal Server Error" and How Do I Fix It?
This error means there is a problem on the server side. A server error can be caused by any number of things from...
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 FreeTop 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
Top GitHub Comments
Thank you for the quick fix and the amazing project 💯
@all-contributors add @mgranderath for bug reporting