# Class: StatusCodeError

Defined in: [api.ts:196](https://github.com/coda/packs-sdk/blob/b2b4c9dba5ca748bdbb94481cc13b5ca3c328ef6/api.ts#L196)

An error that will be thrown by [Fetcher.fetch](../../interfaces/Fetcher/#fetch) when the fetcher response has an HTTP status code of 400 or greater.

This class largely models the `StatusCodeError` from the (now deprecated) `request-promise` library, which has a quirky structure.

## Example

```
let response;
try {
  response = await context.fetcher.fetch({
    method: "GET",
    // Open this URL in your browser to see what the data looks like.
    url: "https://api.artic.edu/api/v1/artworks/123",
  });
} catch (error) {
  // If the request failed because the server returned a 300+ status code.
  if (sdk.StatusCodeError.isStatusCodeError(error)) {
    // Cast the error as a StatusCodeError, for better intellisense.
    let statusError = error as sdk.StatusCodeError;
    // If the API returned an error message in the body, show it to the user.
    let message = statusError.body?.detail;
    if (message) {
      throw new sdk.UserVisibleError(message);
    }
  }
  // The request failed for some other reason. Re-throw the error so that it
  // bubbles up.
  throw error;
}
```

## See

[Fetching remote data - Errors](https://head.coda.io/packs/build/latest/guides/basics/fetcher/#errors)

## Extends

- `Error`

## Properties

### body

> **body**: `any`

Defined in: [api.ts:208](https://github.com/coda/packs-sdk/blob/b2b4c9dba5ca748bdbb94481cc13b5ca3c328ef6/api.ts#L208)

The parsed body of the HTTP response.

______________________________________________________________________

### error

> **error**: `any`

Defined in: [api.ts:212](https://github.com/coda/packs-sdk/blob/b2b4c9dba5ca748bdbb94481cc13b5ca3c328ef6/api.ts#L212)

Alias for [body](#body).

______________________________________________________________________

### name

> **name**: `string` = `'StatusCodeError'`

Defined in: [api.ts:200](https://github.com/coda/packs-sdk/blob/b2b4c9dba5ca748bdbb94481cc13b5ca3c328ef6/api.ts#L200)

The name of the error, for identification purposes.

#### Overrides

`Error.name`

______________________________________________________________________

### options

> **options**: [`FetchRequest`](../../interfaces/FetchRequest/)

Defined in: [api.ts:216](https://github.com/coda/packs-sdk/blob/b2b4c9dba5ca748bdbb94481cc13b5ca3c328ef6/api.ts#L216)

The original fetcher request used to make this HTTP request.

______________________________________________________________________

### response

> **response**: [`StatusCodeErrorResponse`](../../interfaces/StatusCodeErrorResponse/)

Defined in: [api.ts:220](https://github.com/coda/packs-sdk/blob/b2b4c9dba5ca748bdbb94481cc13b5ca3c328ef6/api.ts#L220)

The raw HTTP response, including headers.

______________________________________________________________________

### statusCode

> **statusCode**: `number`

Defined in: [api.ts:204](https://github.com/coda/packs-sdk/blob/b2b4c9dba5ca748bdbb94481cc13b5ca3c328ef6/api.ts#L204)

The HTTP status code, e.g. `404`.

## Methods

### isStatusCodeError()

> `static` **isStatusCodeError**(`err`): `err is StatusCodeError`

Defined in: [api.ts:242](https://github.com/coda/packs-sdk/blob/b2b4c9dba5ca748bdbb94481cc13b5ca3c328ef6/api.ts#L242)

Returns if the error is an instance of StatusCodeError. Note that `instanceof` may not work.

#### Parameters

| Parameter | Type | | --- | --- | | `err` | `any` |

#### Returns

`err is StatusCodeError`
