Skip to content

Commit

Permalink
fix: 🐛 json error bodyresponse
Browse files Browse the repository at this point in the history
  • Loading branch information
touv committed Oct 25, 2023
1 parent 66ea68a commit 4ad1789
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
1 change: 0 additions & 1 deletion packages/core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import writeTo from 'stream-write';
import globalModules from 'global-modules';
import { resolve } from 'path';
import LRU from 'lru-cache';
import _ from 'lodash';
import Engine from './engine';
import Script, { parseCommand } from './script';
import File from './file';
Expand Down
14 changes: 8 additions & 6 deletions packages/core/src/server/errorHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import { httpRequestErrorTotal } from './metrics';
const errorHandler = (request, response) => (error, code = 400) => {
debug('ezs')('Server has caught an error', error);
httpRequestErrorTotal.labels(request.pathName).inc();
if (!response.headersSent) {
response.setHeader('Content-Type', 'text/plain');
response.setHeader('Content-Disposition', 'inline');
response.writeHead(code, { 'X-Error': Parameter.encode(error.toString()) });
response.write(JSON.stringify(error));
if (response.headersSent) {
return response.end();
}
response.end();
const bodyResponse = JSON.stringify(error);
response.setHeader('Content-Type', 'application/json');
response.setHeader('Content-Length', bodyResponse.length);
response.setHeader('Content-Disposition', 'inline');
response.writeHead(code, { 'X-Error': Parameter.encode(error.toString()) });
return response.end(bodyResponse);
};

export default errorHandler;

0 comments on commit 4ad1789

Please sign in to comment.