---
url: https://haihv.github.io/valifetch/api/index/classes/ValifetchError.md
---

# Class: ValifetchError

Defined in: [src/errors/ValifetchError.ts:49](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/errors/ValifetchError.ts#L49)

Custom error class for valifetch errors
Provides structured error information for better error handling

## Extends

* `Error`

## Constructors

### Constructor

> **new ValifetchError**(`options`): `ValifetchError`

Defined in: [src/errors/ValifetchError.ts:70](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/errors/ValifetchError.ts#L70)

Constructs a `ValifetchError`.

#### Parameters

##### options

[`ValifetchErrorOptions`](../type-aliases/ValifetchErrorOptions.md)

Error details: message, code, and optional request/response/validation/cause/responseBody context.

#### Returns

`ValifetchError`

#### Overrides

`Error.constructor`

## Properties

### cause?

> `optional` **cause?**: `unknown`

Defined in: node_modules/typescript/lib/lib.es2022.error.d.ts:24

#### Inherited from

`Error.cause`

***

### code

> `readonly` **code**: [`ErrorCode`](../type-aliases/ErrorCode.md)

Defined in: [src/errors/ValifetchError.ts:51](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/errors/ValifetchError.ts#L51)

Error code for discriminated error handling

***

### message

> **message**: `string`

Defined in: node_modules/typescript/lib/lib.es5.d.ts:1075

#### Inherited from

`Error.message`

***

### name

> **name**: `string`

Defined in: node_modules/typescript/lib/lib.es5.d.ts:1074

#### Inherited from

`Error.name`

***

### request?

> `readonly` `optional` **request?**: `Request`

Defined in: [src/errors/ValifetchError.ts:53](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/errors/ValifetchError.ts#L53)

Original request that caused the error

***

### response?

> `readonly` `optional` **response?**: `Response`

Defined in: [src/errors/ValifetchError.ts:55](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/errors/ValifetchError.ts#L55)

Response received (if any)

***

### responseBody?

> `readonly` `optional` **responseBody?**: `unknown`

Defined in: [src/errors/ValifetchError.ts:64](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/errors/ValifetchError.ts#L64)

Parsed response body on `HTTP_ERROR` (JSON-parsed object/array, or plain
text when the body is not valid JSON) and raw text on `PARSE_ERROR`
(the response body that failed to parse as JSON). `undefined` when the
body could not be read at all.

***

### stack?

> `optional` **stack?**: `string`

Defined in: node_modules/typescript/lib/lib.es5.d.ts:1076

#### Inherited from

`Error.stack`

***

### validation?

> `readonly` `optional` **validation?**: [`ValidationErrorInfo`](../type-aliases/ValidationErrorInfo.md)

Defined in: [src/errors/ValifetchError.ts:57](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/errors/ValifetchError.ts#L57)

Validation error details (if validation failed)

## Accessors

### isAbortError

#### Get Signature

> **get** **isAbortError**(): `boolean`

Defined in: [src/errors/ValifetchError.ts:107](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/errors/ValifetchError.ts#L107)

Check if this is an abort/cancel error

##### Returns

`boolean`

***

### isHttpError

#### Get Signature

> **get** **isHttpError**(): `boolean`

Defined in: [src/errors/ValifetchError.ts:92](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/errors/ValifetchError.ts#L92)

Check if this is an HTTP error (non-2xx status)

##### Returns

`boolean`

***

### isNetworkError

#### Get Signature

> **get** **isNetworkError**(): `boolean`

Defined in: [src/errors/ValifetchError.ts:102](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/errors/ValifetchError.ts#L102)

Check if this is a network error

##### Returns

`boolean`

***

### isParseError

#### Get Signature

> **get** **isParseError**(): `boolean`

Defined in: [src/errors/ValifetchError.ts:112](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/errors/ValifetchError.ts#L112)

Check if this is a parse error (e.g., invalid JSON)

##### Returns

`boolean`

***

### issues

#### Get Signature

> **get** **issues**(): `BaseIssue`<`unknown`>\[]

Defined in: [src/errors/ValifetchError.ts:117](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/errors/ValifetchError.ts#L117)

Get flattened validation issues (convenience)

##### Returns

`BaseIssue`<`unknown`>\[]

***

### isTimeoutError

#### Get Signature

> **get** **isTimeoutError**(): `boolean`

Defined in: [src/errors/ValifetchError.ts:97](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/errors/ValifetchError.ts#L97)

Check if this is a timeout error

##### Returns

`boolean`

***

### isValidationError

#### Get Signature

> **get** **isValidationError**(): `boolean`

Defined in: [src/errors/ValifetchError.ts:87](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/errors/ValifetchError.ts#L87)

Check if this is a validation error

##### Returns

`boolean`

***

### status

#### Get Signature

> **get** **status**(): `number` | `undefined`

Defined in: [src/errors/ValifetchError.ts:127](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/errors/ValifetchError.ts#L127)

HTTP status code (if available)

##### Returns

`number` | `undefined`

***

### statusText

#### Get Signature

> **get** **statusText**(): `string` | `undefined`

Defined in: [src/errors/ValifetchError.ts:132](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/errors/ValifetchError.ts#L132)

HTTP status text (if available)

##### Returns

`string` | `undefined`

***

### target

#### Get Signature

> **get** **target**(): [`ValidationTarget`](../type-aliases/ValidationTarget.md) | `undefined`

Defined in: [src/errors/ValifetchError.ts:122](https://github.com/haihv/valifetch/blob/285835d38a6676b98d2ee1a93e23166c6c834cb2/src/errors/ValifetchError.ts#L122)

Which part of the request/response failed validation (convenience)

##### Returns

[`ValidationTarget`](../type-aliases/ValidationTarget.md) | `undefined`
