Skip to content

Commit

Permalink
Always respond with status code 500, on errors
Browse files Browse the repository at this point in the history
  • Loading branch information
SmartArray committed Aug 3, 2020
1 parent 8efa13e commit 1d4b6f8
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions lib/controllers/Controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,18 @@ class Controller {
}

static sendError(response, error) {
const details = error.details || {};
let code;

if (error.code < 0) {
details.originalCode = error.code;
code = 500;
} else {
code = error.code;
}

const errResponse = {
code: code,
code: error.code,
message: error.error || error.message,
retriable: error.retriable || false,
details: details,
details: error.details,
};

response.status(errResponse.code);
response.json(errResponse);
const serialized = JSON.stringify(errResponse, null, 4);

response.status(500);
response.send(serialized);
response.end();
}

/**
Expand Down

0 comments on commit 1d4b6f8

Please sign in to comment.