@leo-h/create-nodejs-app 1.0.11 → 1.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +0,0 @@
1
- import { DomainError } from "./domain-error";
2
-
3
- export class ValidationError extends DomainError {
4
- public error = "ValidationError";
5
-
6
- constructor(public debug: object | null = null) {
7
- super("Os dados enviados são inválidos.");
8
- }
9
- }
@@ -1,53 +0,0 @@
1
- import { DomainError } from "@/core/errors/domain-error";
2
- import { ValidationError } from "@/core/errors/errors";
3
- import { env } from "@/infra/env";
4
- import { ErrorPresenter } from "@/infra/presenters/error.presenter";
5
- import {
6
- ArgumentsHost,
7
- BadRequestException,
8
- Catch,
9
- ExceptionFilter,
10
- HttpException,
11
- HttpStatus,
12
- InternalServerErrorException,
13
- } from "@nestjs/common";
14
- import { FastifyReply } from "fastify";
15
-
16
- @Catch(DomainError)
17
- export class DomainExceptionFilter implements ExceptionFilter {
18
- catch(exception: DomainError, host: ArgumentsHost): void {
19
- const ctx = host.switchToHttp();
20
- const response = ctx.getResponse<FastifyReply>();
21
-
22
- let httpException: HttpException;
23
-
24
- switch (exception.constructor) {
25
- case ValidationError:
26
- httpException = new BadRequestException(
27
- ErrorPresenter.toHttp(HttpStatus.BAD_REQUEST, exception),
28
- );
29
- break;
30
-
31
- default:
32
- httpException = new InternalServerErrorException(
33
- ErrorPresenter.toHttp(HttpStatus.INTERNAL_SERVER_ERROR, {
34
- error: "InternalServerError",
35
- message: "Desculpe, um erro inesperado ocorreu.",
36
- debug: exception.message,
37
- }),
38
- );
39
- break;
40
- }
41
-
42
- const httpResponse = httpException.getResponse();
43
-
44
- if (
45
- env.NODE_ENV === "production" &&
46
- typeof httpResponse === "object" &&
47
- "debug" in httpResponse
48
- )
49
- delete httpResponse.debug;
50
-
51
- response.status(httpException.getStatus()).send(httpResponse);
52
- }
53
- }
@@ -1,26 +0,0 @@
1
- import { env } from "@/infra/env";
2
- import {
3
- ArgumentsHost,
4
- Catch,
5
- ExceptionFilter,
6
- HttpException,
7
- } from "@nestjs/common";
8
- import { FastifyReply } from "fastify";
9
-
10
- @Catch(HttpException)
11
- export class HttpExceptionFilter implements ExceptionFilter {
12
- catch(httpException: HttpException, host: ArgumentsHost): void {
13
- const ctx = host.switchToHttp();
14
- const response = ctx.getResponse<FastifyReply>();
15
- const httpResponse = httpException.getResponse();
16
-
17
- if (
18
- env.NODE_ENV === "production" &&
19
- typeof httpResponse === "object" &&
20
- "debug" in httpResponse
21
- )
22
- delete httpResponse.debug;
23
-
24
- response.status(httpException.getStatus()).send(httpResponse);
25
- }
26
- }