Skip to content

Class: SchemaValidationException ​

A value which does not match its schema (errno E_SCHEMA_VALIDATION, HTTP 400). The validation engine creates it; DTO.validate() and DTO.validateAsync() throw an InvalidValueException (E_INVALID_VALUE) whose cause is this exception, with the details of the errors.

Extends ​

Constructors ​

Constructor ​

new SchemaValidationException(message, details, original): SchemaValidationException

Parameters ​

message ​

string

details ​

ErrorDetail[]

original ​

unknown

Returns ​

SchemaValidationException

Overrides ​

SchemaException.constructor

Properties ​

_original ​

_original: unknown

The value as it was given to the validation.


appId ​

readonly appId: string

The ID of the application the exception was created in, "Unknown" before the application's options are loaded.

Inherited from ​

SchemaException.appId


appName ​

readonly appName: string

The name of the application the exception was created in, "Unknown" before the application's options are loaded.

Inherited from ​

SchemaException.appName


cause? ​

optional cause?: unknown

Inherited from ​

SchemaException.cause


details ​

details: ErrorDetail[]

The validation errors, one per failed rule (only the first one unless the abortEarly option is false): the message, the path of the invalid value, the error code (type, like string.min) and the context of the message.


err ​

readonly err: string

The name of the exception's class ('OrderNotFoundException'), a copy of name kept as an own property.

Inherited from ​

SchemaException.err


errMsg ​

readonly errMsg: string

The formatted message, a copy of message kept as an own property (sent with the error by the entrypoints).

Inherited from ​

SchemaException.errMsg


errno ​

errno: string | number

The error number or code identifying the error to the clients and the logs ('E_ORDER_NOT_FOUND'); each subclass sets it.

Overrides ​

SchemaException.errno


message ​

message: string

Inherited from ​

SchemaException.message


stack? ​

optional stack?: string

Inherited from ​

SchemaException.stack


stackTraceLimit ​

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 ​

SchemaException.stackTraceLimit


statusCode ​

readonly statusCode: number

The HTTP status the HTTP entrypoints reply with when the exception fails a request; a subclass overrides it (404 for a missing resource…).

Default ​

ts
500

Overrides ​

SchemaException.statusCode

Accessors ​

name ​

Get Signature ​

get name(): string

The name of the exception: the name of its class.

Returns ​

string

The class name.

Inherited from ​

SchemaException.name

Methods ​

annotate() ​

annotate(stripColorCodes?): string

Render the validated value as JSON with each error marked at its place, followed by the list of the error messages; a value which is not an object renders as the first error message.

Parameters ​

stripColorCodes? ​

boolean

Whether to leave out the ANSI color codes (red) marking the errors, for logs and files. Defaults to false (colored).

Returns ​

string

The annotated value, for the terminal or a log.


captureStackTrace() ​

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
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 ​

SchemaException.captureStackTrace


isError() ​

static isError(err): err is SchemaValidationException

Whether an error is a schema validation exception.

Parameters ​

err ​

unknown

The error to test, like the cause of an InvalidValueException.

Returns ​

err is SchemaValidationException

True for a SchemaValidationException (a subclass included).


prepareStackTrace() ​

static prepareStackTrace(err, stackTraces): any

Parameters ​

err ​

Error

stackTraces ​

CallSite[]

Returns ​

any

See ​

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

Inherited from ​

SchemaException.prepareStackTrace

Released under the MIT License.