-
Notifications
You must be signed in to change notification settings - Fork 55
/
errorinfo.js
39 lines (33 loc) · 1.12 KB
/
errorinfo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import Utils from '../util/utils';
var ErrorInfo = (function() {
function ErrorInfo(message, code, statusCode, cause) {
this.message = message;
this.code = code;
this.statusCode = statusCode;
this.cause = cause;
this.href = undefined;
}
ErrorInfo.prototype.toString = function() {
var result = '[' + this.constructor.name;
if(this.message) result += ': ' + this.message;
if(this.statusCode) result += '; statusCode=' + this.statusCode;
if(this.code) result += '; code=' + this.code;
if(this.cause) result += '; cause=' + Utils.inspectError(this.cause);
if(this.href && !(this.message && this.message.indexOf('help.ably.io') > -1)) result += '; see ' + this.href + ' ';
result += ']';
return result;
};
ErrorInfo.fromValues = function(values) {
var result = Utils.mixin(new ErrorInfo(), values);
if (values instanceof Error) {
/* Error.message is not enumerable, so mixin loses the message */
result.message = values.message;
}
if(result.code && !result.href) {
result.href = 'https://help.ably.io/error/' + result.code;
}
return result;
};
return ErrorInfo;
})();
export default ErrorInfo;