Class HttpStatus

Utility class to provide additional functionality around HTTP status codes.

Constructors

Properties

ACCEPTED: HttpStatusEnum = HttpStatusEnum.ACCEPTED
BAD_REQUEST: HttpStatusEnum = HttpStatusEnum.BAD_REQUEST
CREATED: HttpStatusEnum = HttpStatusEnum.CREATED
FORBIDDEN: HttpStatusEnum = HttpStatusEnum.FORBIDDEN
INTERNAL_SERVER_ERROR: HttpStatusEnum = HttpStatusEnum.INTERNAL_SERVER_ERROR
NO_CONTENT: HttpStatusEnum = HttpStatusEnum.NO_CONTENT
NOT_FOUND: HttpStatusEnum = HttpStatusEnum.NOT_FOUND
OK: HttpStatusEnum = HttpStatusEnum.OK
SERVICE_UNAVAILABLE: HttpStatusEnum = HttpStatusEnum.SERVICE_UNAVAILABLE
UNAUTHORIZED: HttpStatusEnum = HttpStatusEnum.UNAUTHORIZED

Methods

  • Validates and converts a numeric HTTP status code to the corresponding HttpStatusEnum value.

    Parameters

    • statusCode: number

      The numeric HTTP status code.

    Returns undefined | HttpStatusEnum

    The corresponding HttpStatusEnum value if valid, or undefined otherwise.

  • Retrieves the textual description of a given HTTP status code.

    Parameters

    • status: HttpStatusEnum

      The HTTP status code.

    Returns string

    The textual description of the status code, or "Unknown Status" if not found.

  • Retrieves both the numeric HTTP status code and its textual description.

    Parameters

    • statusCode: number

      The numeric HTTP status code.

    Returns undefined | { status: HttpStatusEnum; text: string }

    An object containing the status code and its description, or undefined if the code is invalid.