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
Name | Type | Description |
---|---|---|
status | WebStatus | The HTTP status. |
message | string | An error message. |
headers | WebResponseHeaders | Optional custom headers to send to the client. |
Overrides
Error.constructor
Defined in
Properties
headers
• headers: WebResponseHeaders
= {}
Optional custom headers to send to the client.
Defined in
status
• status: WebStatus
The HTTP status.
Defined in
Methods
toString
▸ toString(): string
Converts this WebError to a string.
Returns
string
Defined in
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
Name | Type | Description |
---|---|---|
errorMessageProperty | string | The name |
Returns
A WebResponse to be sent back to the client.