Skip to content

Commit

Permalink
Added version to errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Oct 4, 2018
1 parent cb5f9f5 commit 99fed75
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src.ts/errors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

import { version } from './_version';

// Unknown Error
export const UNKNOWN_ERROR = 'UNKNOWN_ERROR';

Expand Down Expand Up @@ -69,21 +71,23 @@ export function throwError(message: string, code: string, params: any): never {
if (!code) { code = UNKNOWN_ERROR; }
if (!params) { params = {}; }

var messageDetails: Array<string> = [];
Object.keys(params).forEach(function(key) {
let messageDetails: Array<string> = [];
Object.keys(params).forEach((key) => {
try {
messageDetails.push(key + '=' + JSON.stringify(params[key]));
} catch (error) {
messageDetails.push(key + '=' + JSON.stringify(params[key].toString()));
}
});
var reason = message;
messageDetails.push("version=" + version);

let reason = message;
if (messageDetails.length) {
message += ' (' + messageDetails.join(', ') + ')';
}

// @TODO: Any??
var error: any = new Error(message);
let error: any = new Error(message);
error.reason = reason;
error.code = code

Expand Down

0 comments on commit 99fed75

Please sign in to comment.