@ecdt/logger 1.0.7 → 1.0.8
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/examples/express.js +19 -0
- package/package.json +1 -1
- package/src/index.js +1 -0
- package/src/services/logFormatter.js +2 -1
package/examples/express.js
CHANGED
|
@@ -58,6 +58,25 @@ app.get("/throw-error", (_req, res) => {
|
|
|
58
58
|
throw new Error('throw error example');
|
|
59
59
|
})
|
|
60
60
|
|
|
61
|
+
// Simula um erro do Axios (isAxiosError)
|
|
62
|
+
app.get("/axios-error", (_req, res) => {
|
|
63
|
+
const axiosError = new Error('Request failed with status code 503');
|
|
64
|
+
axiosError.isAxiosError = true;
|
|
65
|
+
axiosError.config = {
|
|
66
|
+
method: 'get',
|
|
67
|
+
baseURL: 'https://api.exemplo.com',
|
|
68
|
+
url: '/usuarios',
|
|
69
|
+
headers: { 'Content-Type': 'application/json' },
|
|
70
|
+
};
|
|
71
|
+
axiosError.response = {
|
|
72
|
+
status: 503,
|
|
73
|
+
statusText: 'Service Unavailable',
|
|
74
|
+
headers: { 'content-type': 'application/json' },
|
|
75
|
+
data: { error: 'Serviço temporariamente indisponível' },
|
|
76
|
+
};
|
|
77
|
+
throw axiosError;
|
|
78
|
+
})
|
|
79
|
+
|
|
61
80
|
// Error handler (sempre por último, após as rotas)
|
|
62
81
|
app.use(createErrorCapture());
|
|
63
82
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -19,7 +19,8 @@ function formatLog(tokens, req, res, options = {}){
|
|
|
19
19
|
if(_status >= 500 && res.error && res.error.stack && normalized.includeStackErrors5xx) {
|
|
20
20
|
normalized.extraFields.error = {
|
|
21
21
|
message: res.error.message ?? '',
|
|
22
|
-
stack: res.error.stack
|
|
22
|
+
stack: res.error.stack,
|
|
23
|
+
details: res.errorDetails
|
|
23
24
|
}
|
|
24
25
|
}
|
|
25
26
|
|