ember-api-actions
ember-api-actions copied to clipboard
Add `afterError()` callback
In the current situations any API errors that Ember Data reports are forwarded directly to the caller of the action as a promise rejections. If a model always wants to handle certain errors in a specific way it has to wrap the action method in another method:
_ripen: memberAction({ path: 'ripen' }),
async ripen(...args) {
try {
await this._ripen(...args)
} catch (error) {
if (error instanceof InvalidError) {
// ...
} else {
throw error;
}
}
},
I would like to propose adding support for an afterError() callback that can decide on how to handle errors within the context of the action:
ripen: memberAction({
path: 'ripen',
afterError(error) {
if (error instanceof InvalidError) {
// ...
} else {
throw error;
}
}
}),
@mike-north @alexlafroscia any thoughts on this?
Sounds very reasonable to me! Makes it easy to re-use specific error-handling logic, too.