Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 🐛 error status code #379

Merged
merged 2 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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