@belmonddev/catch-request-express-middleware 3.3.5 → 3.3.6
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/index.js +29 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -113,11 +113,39 @@ const overrideHttpModule = (httpModule, outgoingRequestCb) => {
|
|
|
113
113
|
|
|
114
114
|
reqObject.on('error', (err) => {
|
|
115
115
|
if (responseCb) {
|
|
116
|
+
// Serializar el error con todos sus detalles
|
|
117
|
+
let errorBody;
|
|
118
|
+
if (err && typeof err === 'object') {
|
|
119
|
+
if (err.name === 'AggregateError' && Array.isArray(err.errors)) {
|
|
120
|
+
errorBody = JSON.stringify({
|
|
121
|
+
name: err.name,
|
|
122
|
+
message: err.message,
|
|
123
|
+
stack: err.stack,
|
|
124
|
+
errors: err.errors.map((e) => ({
|
|
125
|
+
name: e?.name,
|
|
126
|
+
message: e?.message,
|
|
127
|
+
code: e?.code,
|
|
128
|
+
stack: e?.stack,
|
|
129
|
+
})),
|
|
130
|
+
});
|
|
131
|
+
} else {
|
|
132
|
+
errorBody = JSON.stringify({
|
|
133
|
+
name: err.name,
|
|
134
|
+
message: err.message,
|
|
135
|
+
code: err.code,
|
|
136
|
+
stack: err.stack,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
} else {
|
|
140
|
+
// Fallback para errores no estándar (string, número, etc.)
|
|
141
|
+
errorBody = JSON.stringify({ message: String(err) });
|
|
142
|
+
}
|
|
143
|
+
|
|
116
144
|
const response = {
|
|
117
145
|
headers: {},
|
|
118
146
|
statusCode: null,
|
|
119
147
|
statusMessage: null,
|
|
120
|
-
body:
|
|
148
|
+
body: errorBody,
|
|
121
149
|
};
|
|
122
150
|
responseCb(response);
|
|
123
151
|
}
|