Documentation
API
TSDLError

TSDLError

This class is exposed from @tsdl/core

import { TSDLError } from "@tsdl/core";

Constructor

server.ts
throw new TSDLError(400);
throw new TSDLError("Unauthorized");

With message

throw new TSDLError(403, "Insuffient permissions");

All HTTP error codes are supported as either number code or the literal string name.

Methods

setMessage(message: string)

Returns this

server.ts
throw new TSDLError(400).setMessage("This is a bad request");

package()

throw new TSDLError(419).package();

static fromPackage(package: unknown)

Returns populated TSDLError instance

const error = TSDLError.fromPackage(package);

Properties

All properties only expose getters and are read-only

message

client.ts
try {
  /* ... */
} catch (e) {
  if (e instanceof TSDLError) {
    alert(`Something went wrong: ${e.message}`);
  }
}

code

client.ts
error.code; // "Bad Request"

numberCode

client.ts
error.numberCode; // 400

validationError

client.ts
const error = new TSDLError<{ issue: string }>().setValidationError({
  issue: "Name is a required field",
});
error.validationError.issue; // "Name is a required field"

semanticErrorMessage

Get an error message with semantic information about the source and message.

Probably appropriate for console logs or debugging, not user facing.

client.ts
error.semanticErrorMessage; // "Error: Something went wrong. Source: application"