Skip to main content

Class: WebError

@divine/web-service.WebError

An Error subclass representing an HTTP response.

In addition to the error message, an HTTP status code and — optionally — one or more custom response headers can be associated with the error.

When caught by a WebService, an HTTP response will be constructed from it by invoking its toWebResponse method.

Hierarchy​

  • Error

    ↳ WebError

Constructors​

constructor​

• new WebError(status, message, headers?)

Constructs an HTTP error/status response.

Parameters​

NameTypeDescription
statusWebStatusThe HTTP status.
messagestringAn error message.
headersWebResponseHeadersOptional custom headers to send to the client.

Overrides​

Error.constructor

Defined in​

web-service/src/error.ts:20

Properties​

headers​

• headers: WebResponseHeaders = {}

Optional custom headers to send to the client.

Defined in​

web-service/src/error.ts:20


status​

• status: WebStatus

The HTTP status.

Defined in​

web-service/src/error.ts:20

Methods​

toString​

▸ toString(): string

Converts this WebError to a string.

Returns​

string

Defined in​

web-service/src/error.ts:25


toWebResponse​

▸ toWebResponse(errorMessageProperty): WebResponse

Converts this WebError to a WebResponse.

By default, a JSON-ish object will be returned with a single property specified by the errorMessageProperty parameter holding the error message. However, subclasses are free to override this method to provide custom error responses. (Alternatively, setErrorHandler can be used to provide per-service customization of any kind of errors/exceptions.)

Parameters​

NameTypeDescription
errorMessagePropertystringThe name

Returns​

WebResponse

A WebResponse to be sent back to the client.

Defined in​

web-service/src/error.ts:40