Skip to content

Commit

Permalink
getHTTPMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
afontainec committed May 29, 2020
1 parent 6604b57 commit a39a786
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 2 additions & 3 deletions models/ErrorHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ class ErrorHandler {

getHTTPMessage(error) {
error = error || {};
const translation = this.ERROR_TRANSLATE[error.chinchayCode];
if (!translation) return 'Internal Error';
return translation.message;
const translation = this.ERROR_TRANSLATE[error.chinchayCode] || {};
return translation.message || error.chinchayMessage || 'Internal Error';
}

getHTTPCodeAndMessage(error) {
Expand Down
8 changes: 8 additions & 0 deletions test/models/ErrorHandler/getHTTPMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ describe('Error Handler intialize', () => {
assert.equal(message, expected);
});

it('code is not in translate but has chinchayMessage', async () => {
const error = { chinchayCode: 427031, chinchayMessage: 'this is the error' };
const handler = new ErrorHandler();
const message = handler.getHTTPMessage(error);
const expected = 'this is the error';
assert.equal(message, expected);
});

it('error is undefined', async () => {
const handler = new ErrorHandler();
const message = handler.getHTTPMessage();
Expand Down

0 comments on commit a39a786

Please sign in to comment.