#

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

# DS.AdapterError Class

Defined in: `addon/-private/adapters/errors.js:10`
Module: ember-data

A `DS.AdapterError` is used by an adapter to signal that an error occurred during a request to an external API. It indicates a generic error, and subclasses are used to indicate specific error states. The following subclasses are provided:

- `DS.InvalidError`
- `DS.TimeoutError`
- `DS.AbortError`
- `DS.UnauthorizedError`
- `DS.ForbiddenError`
- `DS.NotFoundError`
- `DS.ConflictError`
- `DS.ServerError`

To create a custom error to signal a specific error state in communicating with an external API, extend the `DS.AdapterError`. For example, if the external API exclusively used HTTP `503 Service Unavailable` to indicate it was closed for maintenance:

    import DS from 'ember-data';

    export default DS.AdapterError.extend({ message: "Down for maintenance." });

This error would then be returned by an adapter's `handleResponse` method:

    import DS from 'ember-data';
    import MaintenanceError from './maintenance-error';

    export default DS.JSONAPIAdapter.extend({
      handleResponse(status) {
        if (503 === status) {
          return new MaintenanceError();
        }

        return this._super(...arguments);
      }
    });

And can then be detected in an application and used to send the user to an `under-maintenance` route:

    import Route from '@ember/routing/route';
    import MaintenanceError from '../adapters/maintenance-error';

    export default Route.extend({
      actions: {
        error(error, transition) {
          if (error instanceof MaintenanceError) {
            this.transitionTo('under-maintenance');
            return;
          }

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

- Index

## Item Index