@my-swu/simulator-client / EngineHttpError
Class: EngineHttpError
Defined in: packages/ts-sdk/src/internal/errors.ts:108
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:
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
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:
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:135
Creates one HTTP error with normalized response context.
Parameters
message
string
options
Returns
EngineHttpError
Overrides
Error.constructor
Properties
cause?
Example:
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 } })
optionalcause?: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:
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)
readonlycode:string|undefined
Defined in: packages/ts-sdk/src/internal/errors.ts:112
Engine error code when available.
message
Example:
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:
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)
readonlymethod:string|undefined
Defined in: packages/ts-sdk/src/internal/errors.ts:116
HTTP method used for the failed request.
name
Example:
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:
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)
readonlypayload:unknown
Defined in: packages/ts-sdk/src/internal/errors.ts:120
Parsed malformed JSON payload when available.
responseText
Example:
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)
readonlyresponseText:string|undefined
Defined in: packages/ts-sdk/src/internal/errors.ts:124
Raw response text when available.
stack?
Example:
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)
optionalstack?: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:
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)
readonlystatus:number
Defined in: packages/ts-sdk/src/internal/errors.ts:128
HTTP response status.
url
Example:
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)
readonlyurl:string|undefined
Defined in: packages/ts-sdk/src/internal/errors.ts:132
Fully resolved request URL.
stackTraceLimit
Example:
Error.stackTraceLimit = 20
staticstackTraceLimit: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:
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)
staticcaptureStackTrace(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.
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:
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:
Error.prepareStackTrace = (error, stackTraces) => `${error.name}: ${stackTraces.length} frames`
staticprepareStackTrace(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
