Skip to content

Documentation / @ember-data/adapter / error / UnauthorizedError

Defined in: packages/adapter/src/error.js:255

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
js
import { UnauthorizedError } from '@ember-data/adapter/error';

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
  }
}

UnauthorizedError

ts
class UnauthorizedError(errors, message): void;

Defined in: packages/adapter/src/error.js:255

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
js
import { UnauthorizedError } from '@ember-data/adapter/error';

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
  }
}

UnauthorizedError

Parameters

errors

any

message

any

Returns

void

Properties

extend()

ts
static extend: (__namedParameters) => {
(errors, message): void;
  extend: ({ message: defaultMessage }?: {}) => { (errors: any, message: any): void; prototype: any; extend: ...; };
  prototype: any;
};

Defined in: packages/adapter/src/error.js:112

Parameters

__namedParameters

Returns

ts
(errors, message): void;
Parameters
errors

any

message

any

Returns

void

extend
ts
extend: ({ message: defaultMessage }?: {}) => { (errors: any, message: any): void; prototype: any; extend: ...; };
prototype
ts
prototype: any;

Released under the MIT License.