#

API Docs for: v3.8.1
Show: Inherited Protected Private Deprecated

# DS.UnauthorizedError Class

Extends AdapterError
Defined in: `addon/-private/adapters/errors.js:234`
Module: ember-data

A `DS.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:

    import Route from '@ember/routing/route';
    import DS from 'ember-data';

    const { UnauthorizedError } = DS;

    export default Route.extend({
      actions: {
        error(error, transition) {
          if (error instanceof UnauthorizedError) {
            // go to the sign in route
            this.transitionTo('login');
            return;
          }

          // ...other error handling logic
        }
      }
    });

- Index

## Item Index