mirror of
https://github.com/ershisan99/flashcards-api.git
synced 2025-12-18 12:33:21 +00:00
add email account validation
This commit is contained in:
@@ -1,37 +1,30 @@
|
||||
import {
|
||||
ExceptionFilter,
|
||||
Catch,
|
||||
ArgumentsHost,
|
||||
HttpException,
|
||||
} from '@nestjs/common';
|
||||
import { Request, Response } from 'express';
|
||||
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();
|
||||
const ctx = host.switchToHttp()
|
||||
const response = ctx.getResponse<Response>()
|
||||
const request = ctx.getRequest<Request>()
|
||||
const status = exception.getStatus()
|
||||
if (status === 400) {
|
||||
const errorsResponse = {
|
||||
errorsMessages: [],
|
||||
};
|
||||
const responseBody: any = exception.getResponse();
|
||||
if (typeof responseBody.message === 'object') {
|
||||
responseBody.message.forEach((e) =>
|
||||
errorsResponse.errorsMessages.push(e),
|
||||
);
|
||||
} else {
|
||||
errorsResponse.errorsMessages.push(responseBody.message);
|
||||
}
|
||||
response.status(status).json(errorsResponse);
|
||||
const responseBody: any = exception.getResponse()
|
||||
if (typeof responseBody.message === 'object') {
|
||||
responseBody.message.forEach(e => errorsResponse.errorsMessages.push(e))
|
||||
} else {
|
||||
errorsResponse.errorsMessages.push(responseBody.message)
|
||||
}
|
||||
response.status(status).json(errorsResponse)
|
||||
} else {
|
||||
response.status(status).json({
|
||||
statusCode: status,
|
||||
timestamp: new Date().toISOString(),
|
||||
path: request.url,
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user