---
title: "ElysiaError"
description: "Elysia API reference for ElysiaError."
url: "https://next.elysiajs.com/reference/classes/elysiaerror/"
---

# ElysiaError

## Members

### Properties

| Property                                                           | Description                                                                                                                                                                                                    |
| ------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [cause](/reference/classes/elysiaerror/#cause)                     | The cause of the error.                                                                                                                                                                                        |
| [code](/reference/classes/elysiaerror/#code)                       | Stable machine-readable token served in the `code` member, the same contract a [HTTPError.id](/reference/classes/httperror/#id) class speaks (set per subclass)                                                |
| [message](/reference/classes/elysiaerror/#message)                 | -                                                                                                                                                                                                              |
| [name](/reference/classes/elysiaerror/#name)                       | -                                                                                                                                                                                                              |
| [response](/reference/classes/elysiaerror/#response)               | -                                                                                                                                                                                                              |
| [stack](/reference/classes/elysiaerror/#stack)                     | -                                                                                                                                                                                                              |
| [status](/reference/classes/elysiaerror/#status)                   | -                                                                                                                                                                                                              |
| [type](/reference/classes/elysiaerror/#type)                       | RFC 9457 problem type served in the `type` member. Mirrors `code`, or resolves to `<typeBase>/<code>` once [HTTPError.typeBase](/reference/classes/httperror/#typebase) is set. Defined on the prototype below |
| [stackTraceLimit](/reference/classes/elysiaerror/#stacktracelimit) | The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`).                             |

### Methods

| Method                                                                 | Description                                                                                                                                                                |
| ---------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [toResponse](/reference/classes/elysiaerror/#toresponse)               | -                                                                                                                                                                          |
| [captureStackTrace](/reference/classes/elysiaerror/#capturestacktrace) | Creates a `.stack` property on `targetObject`, which when accessed returns a string representing the location in the code at which `Error.captureStackTrace()` was called. |
| [isError](/reference/classes/elysiaerror/#iserror)                     | Indicates whether the argument provided is a built-in Error instance or not.                                                                                               |
| [prepareStackTrace](/reference/classes/elysiaerror/#preparestacktrace) | -                                                                                                                                                                          |

Defined in: elysia/dist/error.d.ts:6

## Extends

- `Error`

## Extended by

- [`InternalServerError`](/reference/classes/internalservererror/)
- [`InvalidCookie`](/reference/classes/invalidcookie/)
- [`NotFound`](/reference/classes/notfound/)
- [`ParseError`](/reference/classes/parseerror/)
- [`ValidationError`](/reference/classes/validationerror/)

## Type Parameters

| Type Parameter                | Default type |
| ----------------------------- | ------------ |
| `Status` *extends* `number`   | `number`     |
| `Response` *extends* `string` | `string`     |

## Constructors

### Constructor

```ts
new ElysiaError<Status, Response>(message, cause?): ElysiaError<Status, Response>;
```

Defined in: elysia/dist/error.d.ts:20

#### Parameters

| Parameter | Type     |
| --------- | -------- |
| `message` | `string` |
| `cause?`  | `Error`  |

#### Returns

`ElysiaError`<`Status`, `Response`>

#### Overrides

```ts
Error.constructor
```

## Properties

### cause?

```ts
optional cause?: unknown;
```

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

The cause of the error.

#### Inherited from

```ts
Error.cause
```

***

### code?

```ts
readonly optional code?: string;
```

Defined in: elysia/dist/error.d.ts:13

Stable machine-readable token served in the `code` member, the same contract a [HTTPError.id](/reference/classes/httperror/#id) class speaks (set per subclass)

***

### message

```ts
message: string;
```

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

#### Inherited from

```ts
Error.message
```

***

### name

```ts
name: string;
```

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

#### Inherited from

```ts
Error.name
```

***

### response?

```ts
optional response?: Response;
```

Defined in: elysia/dist/error.d.ts:8

***

### stack?

```ts
optional stack?: string;
```

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

#### Inherited from

```ts
Error.stack
```

***

### status?

```ts
optional status?: Status;
```

Defined in: elysia/dist/error.d.ts:7

***

### type?

```ts
optional type?: string;
```

Defined in: elysia/dist/error.d.ts:19

RFC 9457 problem type served in the `type` member. Mirrors `code`, or resolves to `<typeBase>/<code>` once [HTTPError.typeBase](/reference/classes/httperror/#typebase) is set. Defined on the prototype below

***

### stackTraceLimit

```ts
static stackTraceLimit: number;
```

Defined in: @types/node/globals.d.ts:68

The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`).

The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured *after* the value has been changed.

If set to a non-number value, or set to a negative number, stack traces will not capture any frames.

#### Inherited from

```ts
Error.stackTraceLimit
```

## Methods

### toResponse()

```ts
toResponse(headers?): Response;
```

Defined in: elysia/dist/error.d.ts:21

#### Parameters

| Parameter  | Type                      |
| ---------- | ------------------------- |
| `headers?` | `Record`<`string`, `any`> |

#### Returns

`Response`

***

### captureStackTrace()

#### Call Signature

```ts
static captureStackTrace(targetObject, constructorOpt?): void;
```

Defined in: @types/node/globals.d.ts:52

Creates a `.stack` property on `targetObject`, which when accessed returns a string representing the location in the code at which `Error.captureStackTrace()` was called.

```js
const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack;  // Similar to `new Error().stack`
```

The first line of the trace will be prefixed with `${myObject.name}: ${myObject.message}`.

The optional `constructorOpt` argument accepts a function. If given, all frames above `constructorOpt`, including `constructorOpt`, will be omitted from the generated stack trace.

The `constructorOpt` argument is useful for hiding implementation details of error generation from the user. For instance:

```js
function a() {
  b();
}

function b() {
  c();
}

function c() {
  // Create an error without stack trace to avoid calculating the stack trace twice.
  const { stackTraceLimit } = Error;
  Error.stackTraceLimit = 0;
  const error = new Error();
  Error.stackTraceLimit = stackTraceLimit;

  // Capture the stack trace above function b
  Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
  throw error;
}

a();
```

##### Parameters

| Parameter         | Type       |
| ----------------- | ---------- |
| `targetObject`    | `object`   |
| `constructorOpt?` | `Function` |

##### Returns

`void`

##### Inherited from

```ts
Error.captureStackTrace
```

#### Call Signature

```ts
static captureStackTrace(targetObject, constructorOpt?): void;
```

Defined in: bun-types/globals.d.ts:1081

Create .stack property on a target object

##### Parameters

| Parameter         | Type       |
| ----------------- | ---------- |
| `targetObject`    | `object`   |
| `constructorOpt?` | `Function` |

##### Returns

`void`

##### Inherited from

```ts
Error.captureStackTrace
```

***

### isError()

#### Call Signature

```ts
static isError(error): error is Error;
```

Defined in: typescript/lib/lib.esnext.error.d.ts:21

Indicates whether the argument provided is a built-in Error instance or not.

##### Parameters

| Parameter | Type      |
| --------- | --------- |
| `error`   | `unknown` |

##### Returns

`error is Error`

##### Inherited from

```ts
Error.isError
```

#### Call Signature

```ts
static isError(value): value is Error;
```

Defined in: bun-types/globals.d.ts:1076

Check if a value is an instance of Error

##### Parameters

| Parameter | Type      | Description        |
| --------- | --------- | ------------------ |
| `value`   | `unknown` | The value to check |

##### Returns

`value is Error`

True if the value is an instance of Error, false otherwise

##### Inherited from

```ts
Error.isError
```

***

### prepareStackTrace()

```ts
static prepareStackTrace(err, stackTraces): any;
```

Defined in: @types/node/globals.d.ts:56

#### Parameters

| Parameter     | Type          |
| ------------- | ------------- |
| `err`         | `Error`       |
| `stackTraces` | `CallSite`\[] |

#### Returns

`any`

#### See

<https://v8.dev/docs/stack-trace-api#customizing-stack-traces>

#### Inherited from

```ts
Error.prepareStackTrace
```
