> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tappify.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# TapServerError

> The error a vendor server throws to answer a Tappify call with a code and a message the owner sees.

The error a vendor server throws to answer a Tappify call with a code and a
message the owner sees.

## Remarks

`createTappifyHandler` catches it and answers `{ error: { code, message } }`
with `status`, or 400 when no status was given; the host relays both to the
calling mount, where they arrive as the `error` of `useTapServer`. Pick a code
of your own and keep it stable — the SDK's own codes are `SERVER_ERROR_CODES` —
and write the message for the owner, who reads it on screen.

## Example

```ts theme={null}
import { TapServerError } from '@tappify/extension-sdk/server';

function assertRange(days: number) {
  if (days > 0) return;
  throw new TapServerError(
    'RANGE_TOO_SHORT',
    'getSummary needs a range of at least one day. Widen the date picker, then retry.',
    400,
  );
}
```

## Extends

* `Error`

## Constructors

### Constructor

```ts theme={null}
new TapServerError(
   code, 
   message, 
   status?
): TapServerError;
```

#### Parameters

##### code

`string`

##### message

`string`

##### status?

`number`

#### Returns

`TapServerError`

#### Overrides

```ts theme={null}
Error.constructor
```

## Properties

### code

```ts theme={null}
readonly code: string;
```

***

### message

```ts theme={null}
message: string;
```

#### Inherited from

```ts theme={null}
Error.message
```

***

### name

```ts theme={null}
name: string;
```

#### Inherited from

```ts theme={null}
Error.name
```

***

### stack?

```ts theme={null}
optional stack?: string;
```

#### Inherited from

```ts theme={null}
Error.stack
```

***

### status

```ts theme={null}
readonly status: number | undefined;
```

***

### stackTraceLimit

```ts theme={null}
static stackTraceLimit: number;
```

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 theme={null}
Error.stackTraceLimit
```

## Methods

### toJSON()

```ts theme={null}
toJSON(): {
  error: {
     code: string;
     message: string;
  };
};
```

The wire body the handler answers with, without the status.

#### Returns

```ts theme={null}
{
  error: {
     code: string;
     message: string;
  };
}
```

##### error

```ts theme={null}
error: {
  code: string;
  message: string;
};
```

###### error.code

```ts theme={null}
code: string;
```

###### error.message

```ts theme={null}
message: string;
```

***

### captureStackTrace()

```ts theme={null}
static captureStackTrace(targetObject, constructorOpt?): void;
```

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 theme={null}
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 theme={null}
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

##### targetObject

`object`

##### constructorOpt?

`Function`

#### Returns

`void`

#### Inherited from

```ts theme={null}
Error.captureStackTrace
```

***

### is()

```ts theme={null}
static is(value): value is TapServerError;
```

Narrows an unknown value to a `TapServerError` by name and by carrying a
string `code`, so it holds across module instances.

#### Parameters

##### value

`unknown`

#### Returns

`value is TapServerError`

***

### prepareStackTrace()

```ts theme={null}
static prepareStackTrace(err, stackTraces): any;
```

#### Parameters

##### err

`Error`

##### stackTraces

`CallSite`\[]

#### Returns

`any`

#### See

[https://v8.dev/docs/stack-trace-api#customizing-stack-traces](https://v8.dev/docs/stack-trace-api#customizing-stack-traces)

#### Inherited from

```ts theme={null}
Error.prepareStackTrace
```
