-
Notifications
You must be signed in to change notification settings - Fork 114
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
Custom responses for failed actions #322
Conversation
To be clear you're proposing in device actions: TestDriver.prototype.customError = function(cb) {
cb({statusCode: 401, properties: {message: 'custom error message'}});
} This would return the following http response:
Today if anything is passed back in the first parameter to the callback it returns a 500 with no body. My only issue with the PR is syntax for returning the error. We were thinking about adding a custom error object possibly on the zetta driver that takes a status code and message. Maybe something like: TestDriver.prototype.customError = function(cb) {
cb(new Driver.ActionError(401, 'custom error message'));
// Also using js Error would also work, could set the message property and assume 500 status code.
cb(new Error('custom error message'));
} |
I'm fine with that approach, I'll make those changes. There isn't going to be any problem with actions that previously returned a 500 error with no body having a body after this change? |
We don't believe so. We'll do some testing with our clients but all so far just look for a non 500 status code. |
Added the error. Need to update the callback handler to use it still. |
env.response.statusCode = statusCode; | ||
env.response.body = { | ||
class: ['action-error'], | ||
properties: err.properties, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should just be properties
not err.properties
Message isn't getting passed in the two other cases. Line 544
+1 Thanks! |
We have a couple of cases where we need to know why an action failed. We could come up with some work around with the server log or monitored properties, but that is not an ideal way to handle errors.
This is written such that existing callbacks will not be affected. The
err
object must have a "properties" member for the behavior to be triggered. I also added a test case to validate the Siren response.