Skip to content

Add afterError() callback #446

Description

@Turbo87

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?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions