Skip to content

@my-swu/simulator-client


@my-swu/simulator-client / EngineHttpError

Class: EngineHttpError ​

Defined in: packages/ts-sdk/src/internal/errors.ts:298

Error thrown for non-2xx HTTP responses from the simulator server.

When the response body matches the API error schema, code contains the server error code. Malformed JSON or non-schema error bodies are preserved in payload or responseText.

Example:

ts
import { EngineHttpError, createSimulatorClient } from '@my-swu/simulator-client'

// Point this at the simulator HTTP origin.
const simulatorClient = createSimulatorClient({
  baseUrl: 'http://127.0.0.1:4000',
})

try {
  // Missing resources reject with structured EngineHttpError details.
  await simulatorClient.matches.get('missing-match')
}
catch (error) {
  if (error instanceof EngineHttpError) {
    console.error(error.status, error.code)
  }
}

Example ​

ts
import { EngineHttpError } from '@my-swu/simulator-client'

const httpError = new EngineHttpError('match not found', {
  status: 404,
  code: 'match_not_found',
  method: 'GET',
  url: 'http://127.0.0.1:4000/api/matches/missing',
})

console.log(httpError.status, httpError.code)

See ​

https://simulator-sdk.my-swu.com/guide/errors

Extends ​

  • Error

Constructors ​

Constructor ​

Example:

ts
import { EngineHttpError } from '@my-swu/simulator-client'

// Build one stable error object for UI or logger tests.
const errorMessage = 'match not found'
const errorOptions = {
  status: 404,
  code: 'match_not_found',
  method: 'GET',
  url: 'http://127.0.0.1:4000/api/matches/missing',
}

const httpError = new EngineHttpError(errorMessage, errorOptions)

new EngineHttpError(message, options): EngineHttpError

Defined in: packages/ts-sdk/src/internal/errors.ts:325

Creates one HTTP error with normalized response context.

Parameters ​

message ​

string

options ​

EngineHttpErrorOptions

Returns ​

EngineHttpError

Overrides ​

Error.constructor

Properties ​

cause? ​

Example:

ts
import { EngineHttpError } from '@my-swu/simulator-client'

// Build one stable error object for UI or logger tests.
const errorMessage = 'match not found'
const errorOptions = {
  status: 404,
  code: 'match_not_found',
  method: 'GET',
  url: 'http://127.0.0.1:4000/api/matches/missing',
}

const cause = new Error(errorMessage)
const httpError = new EngineHttpError(errorMessage, { ...errorOptions, payload: { cause } })

optional cause?: unknown

Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es2022.error.d.ts:26

Inherited from ​

Error.cause


code ​

Example:

ts
import { EngineHttpError } from '@my-swu/simulator-client'

// Construct directly when testing HTTP error handling helpers.
const httpError = new EngineHttpError('match not found', {
  status: 404,
  code: 'match_not_found',
  method: 'GET',
})

const { code: errorCode } = httpError

console.log(errorCode)

readonly code: string | undefined

Defined in: packages/ts-sdk/src/internal/errors.ts:302

Engine error code when available.


message ​

Example:

ts
import { EngineHttpError } from '@my-swu/simulator-client'

// Construct directly when testing HTTP error handling helpers.
const httpError = new EngineHttpError('match not found', {
  status: 404,
  code: 'match_not_found',
  method: 'GET',
})

const { message } = httpError

console.log(message)

message: string

Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es5.d.ts:1077

Inherited from ​

Error.message


method ​

Example:

ts
import { EngineHttpError } from '@my-swu/simulator-client'

// Construct directly when testing HTTP error handling helpers.
const httpError = new EngineHttpError('match not found', {
  status: 404,
  code: 'match_not_found',
  method: 'GET',
})

const { method: httpMethod } = httpError

console.log(httpMethod)

readonly method: string | undefined

Defined in: packages/ts-sdk/src/internal/errors.ts:306

HTTP method used for the failed request.


name ​

Example:

ts
import { EngineHttpError } from '@my-swu/simulator-client'

// Construct directly when testing HTTP error handling helpers.
const httpError = new EngineHttpError('match not found', {
  status: 404,
  code: 'match_not_found',
  method: 'GET',
})

const { name } = httpError

console.log(name)

name: string

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

Inherited from ​

Error.name


payload ​

Example:

ts
import { EngineHttpError } from '@my-swu/simulator-client'

// Construct directly when testing HTTP error handling helpers.
const httpError = new EngineHttpError('match not found', {
  status: 404,
  code: 'match_not_found',
  method: 'GET',
})

const { payload } = httpError

console.log(payload)

readonly payload: unknown

Defined in: packages/ts-sdk/src/internal/errors.ts:310

Parsed malformed JSON payload when available.


responseText ​

Example:

ts
import { EngineHttpError } from '@my-swu/simulator-client'

// Construct directly when testing HTTP error handling helpers.
const httpError = new EngineHttpError('match not found', {
  status: 404,
  code: 'match_not_found',
  method: 'GET',
})

const { responseText } = httpError

console.log(responseText)

readonly responseText: string | undefined

Defined in: packages/ts-sdk/src/internal/errors.ts:314

Raw response text when available.


stack? ​

Example:

ts
import { EngineHttpError } from '@my-swu/simulator-client'

// Construct directly when testing HTTP error handling helpers.
const httpError = new EngineHttpError('match not found', {
  status: 404,
  code: 'match_not_found',
  method: 'GET',
})

const { stack } = httpError

console.log(stack)

optional stack?: string

Defined in: node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/lib/lib.es5.d.ts:1078

Inherited from ​

Error.stack


status ​

Example:

ts
import { EngineHttpError } from '@my-swu/simulator-client'

// Construct directly when testing HTTP error handling helpers.
const httpError = new EngineHttpError('match not found', {
  status: 404,
  code: 'match_not_found',
  method: 'GET',
})

const { status: healthStatus } = httpError

console.log(healthStatus)

readonly status: number

Defined in: packages/ts-sdk/src/internal/errors.ts:318

HTTP response status.


url ​

Example:

ts
import { EngineHttpError } from '@my-swu/simulator-client'

// Construct directly when testing HTTP error handling helpers.
const httpError = new EngineHttpError('match not found', {
  status: 404,
  code: 'match_not_found',
  method: 'GET',
})

const { url: requestUrl } = httpError

console.log(requestUrl)

readonly url: string | undefined

Defined in: packages/ts-sdk/src/internal/errors.ts:322

Fully resolved request URL.


stackTraceLimit ​

Example:

ts
Error.stackTraceLimit = 20

static stackTraceLimit: number

Defined in: node_modules/.pnpm/@types+node@24.12.2/node_modules/@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 ​

Error.stackTraceLimit

Methods ​

captureStackTrace() ​

Example:

ts
import { EngineHttpError } from '@my-swu/simulator-client'

// Build one stable error object for UI or logger tests.
const errorMessage = 'match not found'
const errorOptions = {
  status: 404,
  code: 'match_not_found',
  method: 'GET',
  url: 'http://127.0.0.1:4000/api/matches/missing',
}

const httpError = new EngineHttpError(errorMessage, errorOptions)
Error.captureStackTrace(httpError, EngineHttpError)

static captureStackTrace(targetObject, constructorOpt?): void

Defined in: node_modules/.pnpm/@types+node@24.12.2/node_modules/@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 ​

targetObject ​

object

constructorOpt? ​

Function

Returns ​

void

Inherited from ​

Error.captureStackTrace


prepareStackTrace() ​

Example:

ts
Error.prepareStackTrace = (error, stackTraces) => `${error.name}: ${stackTraces.length} frames`

static prepareStackTrace(err, stackTraces): any

Defined in: node_modules/.pnpm/@types+node@24.12.2/node_modules/@types/node/globals.d.ts:56

Parameters ​

err ​

Error

stackTraces ​

CallSite[]

Returns ​

any

See ​

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

Inherited from ​

Error.prepareStackTrace

Released under the MIT License.