Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

nestjs Built-in HTTP exceptions

BadRequestException
UnauthorizedException
NotFoundException
ForbiddenException
NotAcceptableException
RequestTimeoutException
ConflictException
GoneException
HttpVersionNotSupportedException
PayloadTooLargeException
UnsupportedMediaTypeException
UnprocessableEntityException
InternalServerErrorException
NotImplementedException
ImATeapotException
MethodNotAllowedException
BadGatewayException
ServiceUnavailableException
GatewayTimeoutException
PreconditionFailedException
Comment

nestjs return error response

throw new HttpException('Forbidden', HttpStatus.FORBIDDEN);
// or
throw new HttpException('Not found', HttpStatus.NOT_FOUND);
Comment

nestjs return error response

throw new HttpException('Forbidden', HttpStatus.FORBIDDEN);
// or
throw new HttpException(`Not found`, HttpStatus.NOT_FOUND);
Comment

nest js http exceptions

import { ExceptionFilter, Catch, ArgumentsHost, HttpException } from '@nestjs/common';
import { Request, Response } from 'express';

@Catch(HttpException)
export class HttpExceptionFilter implements ExceptionFilter {
  catch(exception: HttpException, host: ArgumentsHost) {
    const ctx = host.switchToHttp();
    const response = ctx.getResponse<Response>();
    const request = ctx.getRequest<Request>();
    const status = exception.getStatus();

    response
      .status(status)
      .json({
        statusCode: status,
        timestamp: new Date().toISOString(),
        path: request.url,
      });
  }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: change list of objects to list js 
Javascript :: delete list of keys from object javascript 
Javascript :: splice last element from array javascript 
Javascript :: discord.js v13 
Javascript :: format number javascript with comma 
Javascript :: sort array of objects javascript by value 
Javascript :: js redirect 
Javascript :: javascript redirect to homepage 
Javascript :: redirect through javascript 
Javascript :: convert moment date to utc format moment 
Javascript :: math format comma separated in javascript 
Javascript :: function expression and function declaration 
Javascript :: if variable does not exist javascript 
Javascript :: json server 
Javascript :: li key attribute 
Javascript :: Error: [ProtectedRoute] is not a <Route component 
Javascript :: create subcollection firestore 
Javascript :: useMediaQuery react hook 
Javascript :: get DOM node with xpath 
Javascript :: angular adding delay 
Javascript :: array unique values javascript 
Javascript :: pad js 
Javascript :: javascript explode 
Javascript :: get previous route 
Javascript :: javascript random sort array 
Javascript :: javascript display max amount of characters 
Javascript :: javascript get device 
Javascript :: javascript get form data as json 
Javascript :: How to access the request body when POSTing using Node.js and Express 
Javascript :: submit form automatically javascript 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =