errors.js
1.63 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
'use strict';
function RequestError(cause, options, response) {
this.name = 'RequestError';
this.message = String(cause);
this.cause = cause;
this.error = cause; // legacy attribute
this.options = options;
this.response = response;
if (Error.captureStackTrace) { // required for non-V8 environments
Error.captureStackTrace(this);
}
}
RequestError.prototype = Object.create(Error.prototype);
RequestError.prototype.constructor = RequestError;
function StatusCodeError(statusCode, body, options, response) {
this.name = 'StatusCodeError';
this.statusCode = statusCode;
this.message = statusCode + ' - ' + (JSON && JSON.stringify ? JSON.stringify(body) : body);
this.error = body; // legacy attribute
this.options = options;
this.response = response;
if (Error.captureStackTrace) { // required for non-V8 environments
Error.captureStackTrace(this);
}
}
StatusCodeError.prototype = Object.create(Error.prototype);
StatusCodeError.prototype.constructor = StatusCodeError;
function TransformError(cause, options, response) {
this.name = 'TransformError';
this.message = String(cause);
this.cause = cause;
this.error = cause; // legacy attribute
this.options = options;
this.response = response;
if (Error.captureStackTrace) { // required for non-V8 environments
Error.captureStackTrace(this);
}
}
TransformError.prototype = Object.create(Error.prototype);
TransformError.prototype.constructor = TransformError;
module.exports = {
RequestError: RequestError,
StatusCodeError: StatusCodeError,
TransformError: TransformError
};