@lucaapp/service-utils 1.56.4 → 1.56.5
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/dist/lib/api/endpoint.js +10 -5
- package/package.json +1 -1
package/dist/lib/api/endpoint.js
CHANGED
|
@@ -121,8 +121,7 @@ const isTypedError = (error) => {
|
|
|
121
121
|
const validateAndSendResponse = async (expressResponse, response, validResponses, debug) => {
|
|
122
122
|
try {
|
|
123
123
|
(0, assert_1.default)(typeof response.status === 'number');
|
|
124
|
-
|
|
125
|
-
const responseSchema = validResponses.find(responseSchema => responseSchema.status === response.status);
|
|
124
|
+
const responseSchema = validResponses.find(r => r.status === response.status);
|
|
126
125
|
const schema = responseSchema?.schema;
|
|
127
126
|
(0, assert_1.default)(schema);
|
|
128
127
|
if (response.headers) {
|
|
@@ -130,10 +129,16 @@ const validateAndSendResponse = async (expressResponse, response, validResponses
|
|
|
130
129
|
expressResponse.set(header, value);
|
|
131
130
|
});
|
|
132
131
|
}
|
|
133
|
-
|
|
134
|
-
|
|
132
|
+
const validatedResponseBody = await schema
|
|
133
|
+
.parseAsync(response.body)
|
|
134
|
+
.catch(error => {
|
|
135
|
+
if (debug || process.env.NODE_ENV !== 'production') {
|
|
136
|
+
throw error;
|
|
137
|
+
}
|
|
138
|
+
console.error('Response schema validation failed:', error);
|
|
139
|
+
return response.body; // Return original body in production
|
|
140
|
+
});
|
|
135
141
|
if (validatedResponseBody === undefined) {
|
|
136
|
-
// No Content Response
|
|
137
142
|
expressResponse.status(response.status).end();
|
|
138
143
|
return;
|
|
139
144
|
}
|