Skip to content

Commit

Permalink
Merge pull request #379 from Inist-CNRS/fix-error-status
Browse files Browse the repository at this point in the history
fix: 🐛 error status code
  • Loading branch information
touv authored Oct 25, 2023
2 parents 83d70fa + 90142d9 commit 7687045
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
3 changes: 2 additions & 1 deletion packages/core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ ezs.createPipeline = (input, commands, trap) => {
trap.write({
type: 'Fatal run-time error',
scope: 'statements',
message: e.message,
message: e.message.split('\n').shift(),
messageFull: e.message,
sourceError: e.sourceError,
sourceChunk: e.sourceChunk,
});
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function createServer(ezs, serverPort, serverPath, workerId) {
next();
});
app.use((error, request, response, next) => {
errorHandler(request, response)(error, 500);
errorHandler(request, response)(error, 400);
next();
});
const server = controlServer(http.createServer(app));
Expand Down
13 changes: 8 additions & 5 deletions packages/core/src/server/knownPipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ const typeFrom = ({ mimeType }) => (mimeType || 'application/json');
const onlyOne = (item) => (Array.isArray(item) ? item.shift() : item);

const knownPipeline = (ezs) => (request, response, next) => {

if (request.catched || !request.methodMatch(['POST', 'OPTIONS', 'HEAD']) || request.serverPath === false || !request.isPipeline()) {
if (request.catched
|| !request.methodMatch(['POST', 'OPTIONS', 'HEAD'])
|| request.serverPath === false
|| !request.isPipeline()
) {
return next();
}
request.catched = true;
Expand Down Expand Up @@ -120,7 +123,7 @@ const knownPipeline = (ezs) => (request, response, next) => {
decodedStream.destroy();
transformedStream.destroy();
responseStarted();
next(e);
triggerError(e, 400);
});

pipeline(
Expand All @@ -130,7 +133,7 @@ const knownPipeline = (ezs) => (request, response, next) => {
response,
(e) => {
responseStarted();
next(e);
triggerError(e, 500);
}
);

Expand All @@ -142,7 +145,7 @@ const knownPipeline = (ezs) => (request, response, next) => {
})
.on('error', (e) => {
request.unpipe(rawStream);
triggerError(e);
triggerError(e, 500);
})
.once('close', () => {
if (emptyStream) {
Expand Down

0 comments on commit 7687045

Please sign in to comment.