@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.
- package/dist/index.js +1 -1
- package/dist/package.json.js +1 -1
- package/package.json +5 -1
- package/templates/clean/build.config.ts +1 -0
- package/templates/clean/gitignore +132 -0
- package/templates/clean/npmrc +1 -0
- package/templates/fastify/build.config.ts +1 -0
- package/templates/fastify/gitignore +132 -0
- package/templates/fastify/npmrc +1 -0
- package/templates/fastify/package.json +3 -1
- package/templates/fastify/pnpm-lock.yaml +107 -0
- package/templates/nest/gitignore +132 -0
- package/templates/nest/npmrc +1 -0
- package/templates/nest/package.json +3 -2
- package/templates/nest/pnpm-lock.yaml +144 -18
- package/templates/nest/src/core/errors/validation.error.ts +12 -0
- package/templates/nest/src/infra/http/errors/filters/all-exception.filter.ts +31 -0
- package/templates/nest/src/infra/http/errors/filters/domain-exception.filter.ts +39 -0
- package/templates/nest/src/infra/http/errors/internal-server.error.ts +15 -0
- package/templates/nest/src/infra/http/http.module.ts +4 -4
- package/templates/nest/src/infra/http/middlewares/zod-schema-pipe.ts +24 -11
- package/templates/nest/src/infra/http/middlewares/zod-validation-pipe.ts +4 -4
- package/templates/nest/src/infra/presenters/error.presenter.ts +2 -1
- package/templates/nest/src/core/errors/errors.ts +0 -9
- package/templates/nest/src/infra/http/filters/domain-exception.filter.ts +0 -53
- package/templates/nest/src/infra/http/filters/http-exception.filter.ts +0 -26
@@ -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
|
-
}
|