Home Reference Source Test Repository
public class | source

ApiError

Extends:

Error → ApiError

A custom error class to encapsulate errors thrown by FetchUtil.nprApiFetch. Behaves like a generic JavaScript error, but has additional metadata attached to it in case consuming code needs to be able to respond to specific kinds of errors.

Example:

nprOneSDK.setUserStation(123)
    .catch((error) => {
        if (error instanceof ApiError) {
            if (error.statusCode === 401) {
                Logger.debug('The response was a 401!');
            } else {
                Logger.debug('The response was not a 401!');
            }
        }
    });

Constructor Summary

Public Constructor
public

constructor(response: Response, json: Object)

Creates a new, custom error using the Fetch Response object as its basis.

Member Summary

Public Members
public

The headers associated with the response.

public

Contains the decoded JSON of the response, if any.

public

Contains the type of the response (e.g., basic, cors).

public

Contains the URL of the response.

public

The status code of the response (e.g., 400 for a bad request).

public

The status message corresponding to the status code (e.g., Bad Request for 400).

Public Constructors

public constructor(response: Response, json: Object) source

Creates a new, custom error using the Fetch Response object as its basis.

Params:

NameTypeAttributeDescription
response Response

The actual raw Fetch Response from the failed API call

json Object
  • optional
  • default: {}

If available, the decoded JSON from the error response

Public Members

public headers: Headers source

The headers associated with the response.

public json: Object source

Contains the decoded JSON of the response, if any.

public responseType: string source

Contains the type of the response (e.g., basic, cors).

public responseUrl: string source

Contains the URL of the response.

public statusCode: number source

The status code of the response (e.g., 400 for a bad request).

public statusText: string source

The status message corresponding to the status code (e.g., Bad Request for 400).