ctx.throw response
See original GitHub issueHey guys, I saw your response for ctx.throw not supporting a custom response in #194. however I noticed, that it only errors and forces the body when you throw a 500. If I use ctx.throw(400, JSON.stringify({some: "data"}))
it works just fine.
Any chance you would re-consider allowing custom responses for 500 errors too?
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
koa/context.md at master · koajs/koa - GitHub
Many of the context's accessors and methods simply delegate to their ctx.request or ctx.response equivalents for convenience, and are otherwise identical.
Read more >How to make koa ctx.throw() use application/json rather than ...
throw () means any stacktrace is emitted to the server logs and also any custom error message is sent in the response. The...
Read more >Koa - next generation web framework for node.js
ctx.response. A Koa Response object. ctx.state. The recommended namespace for passing information through middleware and to your frontend views.
Read more >Koa cheatsheet - Devhints
The one-page guide to Koa: usage, examples, links, snippets, and more.
Read more >Sending Response with Koa - Medium
To send the response body, we can set the body attribute of ctx . For instance, we can send a response body as...
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
What @AliasT suggested worked.
I didn’t open that one, I just responded to it. But I wanted koa to return a 500 error, have ctx.body be JSON so that the service that is consuming it could print useful errors to the customer.
I Want to use ctx.throw because that stops the request immediatly and doesn’t traverse through any other middleware.
this might work:
but it seems like this feature is just designed for user-level error https://github.com/koajs/koa/blob/master/lib/context.js#L70