From dea909f2beba600ea27387510ab33a44174e0f6a Mon Sep 17 00:00:00 2001 From: Nicolas Thouvenin Date: Tue, 24 Oct 2023 20:54:09 +0200 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=F0=9F=90=9B=20error=20status=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/server/index.js | 2 +- packages/core/src/server/knownPipeline.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/src/server/index.js b/packages/core/src/server/index.js index d8578dda4..ea66e763c 100644 --- a/packages/core/src/server/index.js +++ b/packages/core/src/server/index.js @@ -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)); diff --git a/packages/core/src/server/knownPipeline.js b/packages/core/src/server/knownPipeline.js index 2b5374b02..2c06ec16a 100644 --- a/packages/core/src/server/knownPipeline.js +++ b/packages/core/src/server/knownPipeline.js @@ -142,7 +142,7 @@ const knownPipeline = (ezs) => (request, response, next) => { }) .on('error', (e) => { request.unpipe(rawStream); - triggerError(e); + triggerError(e, 500); }) .once('close', () => { if (emptyStream) { From 90142d9e186c45737cfb86dba5339ce06e879385 Mon Sep 17 00:00:00 2001 From: Nicolas Thouvenin Date: Wed, 25 Oct 2023 06:50:10 +0200 Subject: [PATCH 2/2] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20trigger=20errors?= =?UTF-8?q?=20in=20same=20way?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/index.js | 3 ++- packages/core/src/server/knownPipeline.js | 11 +++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 78eeccf93..60d0d1b5b 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -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, }); diff --git a/packages/core/src/server/knownPipeline.js b/packages/core/src/server/knownPipeline.js index 2c06ec16a..da880795e 100644 --- a/packages/core/src/server/knownPipeline.js +++ b/packages/core/src/server/knownPipeline.js @@ -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; @@ -120,7 +123,7 @@ const knownPipeline = (ezs) => (request, response, next) => { decodedStream.destroy(); transformedStream.destroy(); responseStarted(); - next(e); + triggerError(e, 400); }); pipeline( @@ -130,7 +133,7 @@ const knownPipeline = (ezs) => (request, response, next) => { response, (e) => { responseStarted(); - next(e); + triggerError(e, 500); } );