@tc-libs/error-handler 3.6.0 → 3.8.0
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 +57 -6
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -1,11 +1,62 @@
|
|
|
1
|
-
# error-handler
|
|
1
|
+
# @tc-libs/error-handler
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Gestione centralizzata degli errori HTTP del monorepo.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Il package registra globalmente:
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- `ErrorHttpFilter` come `APP_FILTER`
|
|
8
|
+
- `ErrorMetaGuard` come `APP_GUARD`
|
|
8
9
|
|
|
9
|
-
##
|
|
10
|
+
## Registrazione
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
```ts
|
|
13
|
+
ErrorHandlerModule.register(
|
|
14
|
+
{
|
|
15
|
+
availableLanguages: ['it', 'en'],
|
|
16
|
+
versioning: {
|
|
17
|
+
version: '1',
|
|
18
|
+
},
|
|
19
|
+
repoVersion: '1.0.0',
|
|
20
|
+
},
|
|
21
|
+
true,
|
|
22
|
+
);
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Cosa fa `ErrorHttpFilter`
|
|
26
|
+
|
|
27
|
+
- intercetta eccezioni `ApiError` e fallback generici
|
|
28
|
+
- legge dati request da `@tc-libs/request`
|
|
29
|
+
- traduce validation/import errors tramite `@tc-libs/message`
|
|
30
|
+
- costruisce `_metadata` coerente con `@tc-libs/response`
|
|
31
|
+
- logga tramite `@tc-libs/debugger` quando necessario
|
|
32
|
+
|
|
33
|
+
Il body finale contiene tipicamente:
|
|
34
|
+
|
|
35
|
+
- `message`
|
|
36
|
+
- `data`
|
|
37
|
+
- `errors`
|
|
38
|
+
- `_error`
|
|
39
|
+
- `_metadata`
|
|
40
|
+
|
|
41
|
+
## Decorator `ErrorMeta`
|
|
42
|
+
|
|
43
|
+
Permette di forzare nome classe/funzione mostrati nei log:
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
@ErrorMeta('UserController', 'create')
|
|
47
|
+
@Post()
|
|
48
|
+
create() {}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Se non lo usi, `ErrorMetaGuard` deduce classe e metodo dal contesto Nest.
|
|
52
|
+
|
|
53
|
+
## Quando usarlo
|
|
54
|
+
|
|
55
|
+
Usa questo package se vuoi che tutte le API del progetto restituiscano errori nello stesso formato, con metadata e logging uniformi.
|
|
56
|
+
|
|
57
|
+
## Sviluppo
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
nx build error-handler
|
|
61
|
+
nx test error-handler
|
|
62
|
+
```
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tc-libs/error-handler",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.8.0",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@tc-libs/message": "3.
|
|
6
|
-
"@tc-libs/request": "3.
|
|
7
|
-
"@tc-libs/debugger": "3.
|
|
8
|
-
"@tc-libs/errors": "3.
|
|
9
|
-
"@tc-libs/helper": "3.
|
|
10
|
-
"@tc-libs/response": "3.
|
|
11
|
-
"@tc-libs/error-interface": "3.
|
|
5
|
+
"@tc-libs/message": "3.8.0",
|
|
6
|
+
"@tc-libs/request": "3.8.0",
|
|
7
|
+
"@tc-libs/debugger": "3.8.0",
|
|
8
|
+
"@tc-libs/errors": "3.8.0",
|
|
9
|
+
"@tc-libs/helper": "3.8.0",
|
|
10
|
+
"@tc-libs/response": "3.8.0",
|
|
11
|
+
"@tc-libs/error-interface": "3.8.0",
|
|
12
12
|
"@nestjs/common": "^11.0.12",
|
|
13
13
|
"@nestjs/core": "^11.0.12",
|
|
14
14
|
"class-validator": "^0.14.1",
|