Class ApiError

This class helps distinguish "user" errors (such as calling a method of this library without a required parameter) from remote API errors. When a remote API error occurs (i.e., the server responds with a 4xx or 5xx) an ApiError is thrown.

An ApiError will have a status property with the response's HTTP status code, and a message property with the response body (error message).

try {
await api.getUnreadCounts()
} catch (error) {
if (error instanceof ApiError) {
console.log("Caught an ApiError:")
console.log(`HTTP ${error.status}: ${error.message}`)
} else {
console.log("Some other error:", error)
}

Hierarchy

  • Error
    • ApiError

Constructors

  • Parameters

    • message: string
    • status: number

    Returns ApiError

Methods

  • Create .stack property on a target object

    Parameters

    • targetObject: object
    • OptionalconstructorOpt: Function

    Returns void

Properties

prepareStackTrace?: (err: Error, stackTraces: CallSite[]) => any

Optional override for formatting stack traces

stackTraceLimit: number
cause?: unknown
name: string
message: string
stack?: string
status: number

The HTTP status code of the response.