Class UnauthorizedError

Extends: AdapterError
Defined in: ../adapter/addon/error.js:228
Module: @ember-data/adapter

A UnauthorizedError equates to a HTTP 401 Unauthorized response status. It is used by an adapter to signal that a request to the external API was rejected because authorization is required and has failed or has not yet been provided.

An example use case would be to redirect the user to a login route if a request is unauthorized:

app/routes/application.js
import Route from '@ember/routing/route';
import { UnauthorizedError } from '@ember-data/adapter/error';
import { action } from '@ember/object';

export default class ApplicationRoute extends Route {
  @action
  error(error, transition) {
    if (error instanceof UnauthorizedError) {
      // go to the login route
      this.transitionTo('login');
      return;
    }

    // ...other error handling logic
  }
}

© 2020 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
https://api.emberjs.com/ember-data/3.25/classes/UnauthorizedError