UNPKG

create-nest-template-malahimdev

Version:

Scaffolds a NestJS template with Swagger, global pipes, exception filters, MongoDB connection and response helpers.

38 lines (34 loc) 915 B
import { BadRequestException, InternalServerErrorException, UnauthorizedException } from '@nestjs/common'; export const successResponse = (message: string, data: any = {}) => { return { success: true, message, ...data, }; }; export const errorResponse = { badRequest: (messages: string[], statusCode = 400) => { throw new BadRequestException({ success: false, message: messages, error: 'Bad Request', statusCode, }); }, unauthorized: (messages: string[], statusCode = 401) => { throw new UnauthorizedException({ success: false, message: messages, error: 'Unauthorized', statusCode, }); }, internal: (message = 'Something went wrong', statusCode = 500) => { throw new InternalServerErrorException({ success: false, message: [message], error: 'Internal Server Error', statusCode, }); }, };