-
Notifications
You must be signed in to change notification settings - Fork 44
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
error handling with seneca-web 1.0.0 #103
Comments
@allinwind3344 All action handlers have access to the request and response objects. So to do the above you can do. seneca.act('role:web', {routes: {
prefix: '/',
pin: 'role: user, cmd: *',
map: {
read: {GET: true, alias: '/user/:userId', autoreply:false},
create: {POST: true, alias: '/user', autoreply:false}
}
}}) Then in your handler, seneca.add('role:user,cmd:read', (msg, done) => {
// The req, res provided by the adapter.
var requestObj = msg.request$
var replyObj = msg.response$
// Tell seneca you are done
done()
// It is now up to you to reply
replyObj.xyz // Differs depending on adapter used
}) Do not auto handlers are the only type of web route that can participate in transport. To put it another way request$ and response$ are not transported over the network so cannot be handled in another microservice. |
Maybe it would be good to provide a I'm not sure how this could work in HAPI but with express/connect it would allow the host application to handle errors in a custom error handler. Currently errors are always returned as 500, sending the entire error. |
If it can be made to work generally with all adapters I'm all for it. I want to avoid specific functionality differences where possible. |
Fair enough.... I'll look into this later today. Heading into work now but in ~8-9 hours I'll look into how this can be done in hapi/koa |
After playing with this a bit, it seems that each of the adapters has a method for the host application to handle errors except for connect/express... I've opened tickets on each of the adapters for this and have attached PRs to fix each (see above for tickets) For prosperity, here's how to handle errors in each of the adapters
I've added/updated the test cases in each of the adapters to show some usage of this. (also, @mcdonnelldean, this test case brings HAPI is back up to >80% coverage, so I've bumped it up again) |
@tswaters epic stuff. We'll probably need a doc on this. |
@mcdonnelldean thanks for your explanation! |
how to use boom for exception handling in seneca js ? |
when seneca action encounter fatal error, it may terminate seneca-web.
check the issue #56, can handle error as below:
whether "responder" still exist in seneca-web 1.0.0? if not, how to customize error handling?
The text was updated successfully, but these errors were encountered: