@ecdt/logger 1.0.6 → 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.
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecdt/logger",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "Logger padronização de microsserviços da Econodata",
5
5
  "type": "commonjs",
6
6
  "main": "src/index.js",
package/src/index.js CHANGED
@@ -22,11 +22,34 @@ function createLogger(options = {}) {
22
22
 
23
23
  function createErrorCapture() {
24
24
  return function errorCapture(err, req, res, next) {
25
- res.error = {
25
+ const errorDetails = {
26
26
  message: err?.message,
27
27
  stack: err?.stack
28
+ };
29
+
30
+ if (err?.isAxiosError) {
31
+ const responseData = err.response?.data;
32
+ const dataSummary = typeof responseData === 'string' && responseData.length > 300
33
+ ? responseData.slice(0, 300) + '...[truncated]'
34
+ : responseData;
35
+
36
+ errorDetails.axiosError = {
37
+ config: {
38
+ method: err.config?.method,
39
+ url: err.config?.baseURL ?? err.config?.url,
40
+ headers: err.config?.headers,
41
+ },
42
+ response: {
43
+ status: err.response?.status,
44
+ statusText: err.response?.statusText,
45
+ headers: err.response?.headers,
46
+ data: dataSummary,
47
+ }
48
+ };
28
49
  }
29
- res.status(500).json({ error: res.error.message ?? 'Erro interno no servidor'});
50
+
51
+ res.error = errorDetails;
52
+ res.status(500).json({ error: res.error.message ?? 'Erro interno no servidor' });
30
53
  }
31
54
  }
32
55
 
@@ -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