Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

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
Typescript :: python append elements from one list to anoter 
Typescript :: use pipe in ts file angulr 
Typescript :: flutter constructor default value 
Typescript :: angular images 
Typescript :: switch in typescript 
Typescript :: google sheets query multiple or 
Typescript :: typescript discriminated unions 
Typescript :: subscribe in angular 10 
Typescript :: excel check if value exists in range 
Typescript :: test coverage techniques 
Typescript :: can you make twitter bots in node.js 
Typescript :: testing techniques 
Typescript :: mongodb find documents where two fields are equal 
Typescript :: Header missing on reports odoo 
Typescript :: how to take union of two lists in python 
Typescript :: undetermined number of arguments in function r 
Typescript :: terminal update file metadata 
Typescript :: how to delete a message by its id 
Typescript :: multiple hosts in same role 
Typescript :: when 2 emits on a same chatroom at a time only one is working using socket.io 
Typescript :: subplots in for loop python (no dynamic) 
Typescript :: Exclude code from hints delphi 7 
Typescript :: corpses:2249 Livewire: The published Livewire assets are out of date 
Typescript :: which view should a user query to display the columns associated with the constraints on a table owned by a user? 
Typescript :: are flights still running 
Typescript :: how to write elements of a list as a string with a comma between elements in python 
Typescript :: angular8 PrimeNg tabview 
Typescript :: compare 2 sets python 
Typescript :: swift collection view deselects item when scroll off screen 
Typescript :: How to check that tuple A contains all elements of tuple B python? 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =