Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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 :: tailwind modal react 
Javascript :: nuxt head script content 
Javascript :: install react js 
Javascript :: why does my page reloads on form submission 
Javascript :: javascript get random line from text file 
Javascript :: jquery toggle input checkbox 
Javascript :: react bootstrap card 
Javascript :: adding media queries in makeStyle material react 
Javascript :: JavaScript how to put value 
Javascript :: copy dict js 
Javascript :: how convert object to string and string to object in javascript 
Javascript :: javascript reduce array of objects 
Javascript :: js sort 1 or -1 
Javascript :: array int to string javascript 
Javascript :: keypress javascript 
Javascript :: js filter undefined from array 
Javascript :: get monitor width javascript 
Javascript :: alert.alert react native style 
Javascript :: how to convert to one decimal place javascript 
Javascript :: node get root directory 
Javascript :: redux saga delay 
Javascript :: string interpolation javascript 
Javascript :: angular input value 
Javascript :: javascript display 2 number after comma 
Javascript :: show ajax error wordpress 
Javascript :: react how to create range 
Javascript :: how to get all form values in javascript 
Javascript :: how to show day name in javascript using array 
Javascript :: inline if else javascript 
Javascript :: javascript add class 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =