Options
All
  • Public
  • Public/Protected
  • All
Menu

Class HttpException

Defines the base Nest HTTP exception, which is handled by the default Exceptions Handler. Defines the base Nest HTTP exception, which is handled by the default Exceptions Handler.

see

Base Exceptions

publicapi
see

Base Exceptions

publicapi

Hierarchy

Index

Constructors

constructor

  • Instantiate a plain HTTP Exception.

    example

    throw new HttpException()

    usagenotes

    The constructor arguments define the response and the HTTP response status code.

    • The response argument (required) defines the JSON response body.
    • The status argument (required) defines the HTTP Status Code.

    By default, the JSON response body contains two properties:

    • statusCode: the Http Status Code.
    • message: a short description of the HTTP error by default; override this by supplying a string in the response parameter.

    To override the entire JSON response body, pass an object to the createBody method. Nest will serialize the object and return it as the JSON response body.

    The status argument is required, and should be a valid HTTP status code. Best practice is to use the HttpStatus enum imported from nestjs/common.

    Parameters

    • response: any

      string or object describing the error condition.

    • status: any

      HTTP response status code.

    Returns HttpException

Properties

message

message: string

name

name: string

Private Readonly response

response: string | Record<string, any>

string or object describing the error condition.

Optional stack

stack: string

Private Readonly status

status: number

HTTP response status code.

Static Error

Error: ErrorConstructor

Methods

getResponse

  • getResponse(): any
  • Returns any

getStatus

  • getStatus(): any
  • Returns any

initMessage

  • initMessage(): void
  • Returns void

Static createBody

  • createBody(objectOrError: any, description: any, statusCode: any): object
  • Parameters

    • objectOrError: any
    • description: any
    • statusCode: any

    Returns object

Generated using TypeDoc