@sentzunhat/zacatl 0.0.5 → 0.0.7
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/README.md +192 -111
- package/context.yaml +151 -0
- package/guidelines.yaml +74 -0
- package/mongodb.yaml +29 -0
- package/package.json +33 -2
- package/patterns.yaml +55 -0
- package/src/error/custom.ts +3 -2
- package/src/micro-service/architecture/application/entry-points/rest/common/handler.ts +1 -2
- package/src/micro-service/architecture/application/entry-points/rest/route-handlers/abstract.ts +16 -2
- package/src/micro-service/architecture/application/entry-points/rest/route-handlers/get-route-handler.ts +3 -5
- package/src/micro-service/architecture/application/entry-points/rest/route-handlers/post-route-handler.ts +4 -6
- package/src/micro-service/architecture/application/entry-points/rest/route-handlers/route-handler.ts +1 -2
- package/src/micro-service/architecture/infrastructure/repositories/abstract.ts +94 -18
- package/src/micro-service/architecture/platform/service/service.ts +4 -0
- package/start.md +34 -0
- package/test/unit/micro-service/architecture/application/application.test.ts +19 -2
- package/test/unit/micro-service/architecture/application/entry-points/rest/route-handlers/abstract.test.ts +30 -10
- package/test/unit/micro-service/architecture/application/entry-points/rest/route-handlers/post-route-handler.test.ts +14 -9
- package/test/unit/micro-service/architecture/infrastructure/repositories/abstract.test.ts +6 -9
- package/test/unit/micro-service/architecture/platform/service/service.test.ts +3 -3
- package/src/errors.ts +0 -72
package/src/errors.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { ZodError } from "zod";
|
|
2
|
-
import { isError } from "lodash";
|
|
3
|
-
|
|
4
|
-
import { logger } from "./logs";
|
|
5
|
-
import { FastifyError, FastifyReply, FastifyRequest } from "fastify";
|
|
6
|
-
|
|
7
|
-
const isZodError = (error: unknown): error is ZodError =>
|
|
8
|
-
isError(error) && "ZodError" === error.name;
|
|
9
|
-
|
|
10
|
-
const handleApiError = async (handler: () => Promise<void>) => {
|
|
11
|
-
try {
|
|
12
|
-
await handler();
|
|
13
|
-
} catch (err) {
|
|
14
|
-
const { request, response } = err as {
|
|
15
|
-
request: { data: unknown };
|
|
16
|
-
response: { data: unknown };
|
|
17
|
-
};
|
|
18
|
-
if (request)
|
|
19
|
-
logger.error("request", { logData: { request: { data: request.data } } });
|
|
20
|
-
if (response)
|
|
21
|
-
logger.error("response", {
|
|
22
|
-
logData: { response: { data: response.data } },
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
if (err) {
|
|
26
|
-
logger.error("errored", { logData: { error: err } });
|
|
27
|
-
throw err;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const handleRouteError = (
|
|
33
|
-
error: FastifyError,
|
|
34
|
-
request: FastifyRequest,
|
|
35
|
-
reply: FastifyReply
|
|
36
|
-
) => {
|
|
37
|
-
console.log("====================================");
|
|
38
|
-
console.log({ request });
|
|
39
|
-
console.log("====================================");
|
|
40
|
-
|
|
41
|
-
if (isZodError(error)) {
|
|
42
|
-
const zodError = error as ZodError;
|
|
43
|
-
const logDataZodError = {
|
|
44
|
-
name: zodError.name,
|
|
45
|
-
issues: zodError.issues,
|
|
46
|
-
};
|
|
47
|
-
return reply.status(400).send({ ok: false, error: logDataZodError });
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (error instanceof SyntaxError) {
|
|
51
|
-
reply.status(400).send({ error: "Bad Request", message: error.message });
|
|
52
|
-
} else if (error instanceof ZodError) {
|
|
53
|
-
reply
|
|
54
|
-
.status(422)
|
|
55
|
-
.send({ error: "Validation Error", message: error.errors });
|
|
56
|
-
} else {
|
|
57
|
-
reply
|
|
58
|
-
.status(500)
|
|
59
|
-
.send({ error: "Internal Server Error", message: error.message });
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return reply.status(400).send({
|
|
63
|
-
ok: false,
|
|
64
|
-
error: {
|
|
65
|
-
name: error.name,
|
|
66
|
-
message: error.message,
|
|
67
|
-
error,
|
|
68
|
-
},
|
|
69
|
-
});
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
export { isZodError, handleApiError, handleRouteError };
|