Skip to main content

Exception Types

Keq provides a set of built-in exception types for handling different request error scenarios. These exception classes inherit from standard JavaScript error classes, providing more precise error categorization and handling capabilities.

RequestException

The base class for request exceptions, representing errors that occur during HTTP requests.

class RequestException extends Error {
  constructor(
    statusCode: number,
    message?: string,
    options?: { fatal?: boolean, response?: Response } = {},
  )
}

Parameters:

ParameterTypeDefaultDescription
statusCodenumber-HTTP status code
messagestring-Error message
options.fatalbooleanfalseSet to true to terminate the retry mechanism
options.responseResponse-Associated Response object (if available)

AbortException

Inherits from DOMException, thrown when a request is actively aborted.

class AbortException extends DOMException {
  constructor(message?: string)
}
ParameterTypeDefaultDescription
messagestring-Error message

TimeoutException

Inherits from AbortException, thrown when a request times out. Typically triggered by the .timeout() method.

class TimeoutException extends AbortException {
  constructor(message?: string)
}
ParameterTypeDefaultDescription
messagestring-Error message

MutexException

Thrown when a request is blocked by mutex flow control. Indicates that a request in the same queue is already executing and the new request was rejected.

class MutexException extends Exception {
  constructor(message?: string)
}
ParameterTypeDefaultDescription
messagestring-Error message

TypeException

A parameter type error exception, similar to the standard TypeError, used to identify parameter passing errors.

class TypeException extends TypeError {}
info

In TypeScript projects, you typically won't encounter this exception since the TypeScript compiler catches type errors at compile time. This exception is mainly used for runtime type checking or pure JavaScript projects.

HTTP Status Code Exceptions

Keq provides common HTTP Exceptions, all inheriting from RequestException:

Exception ClassStatus Code
BadRequestException400
UnauthorizedException401
ForbiddenException403
NotFoundedException404
MethodNotAllowedException405
NotAcceptableException406
ProxyAuthenticationRequiredException407
RequestTimeoutException408
ConflictException409
PreconditionFailedException412
ContentTooLargeException413
UriTooLongException414
UnsupportedMediaTypeException415
ImATeapotException418
TooManyRequestsException429
InternalServerErrorException500
NotImplementedException501
BadGatewayException502
ServiceUnavailableException503
GatewayTimeoutException504