1 | 'use strict';
|
2 |
|
3 | var util = require('util');
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | function IdentifiedApiError(){}
|
13 | util.inherits(IdentifiedApiError, Error);
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | function ApiHttpError(statusCode, response, message) {
|
25 | this.name = "ApiHttpError";
|
26 | this.statusCode = statusCode;
|
27 | this.response = response;
|
28 | this.message = message || response
|
29 | || util.format('Unexpected %s status code', statusCode);
|
30 |
|
31 | if (Error.captureStackTrace
|
32 | && typeof Error.captureStackTrace === 'function') {
|
33 | Error.captureStackTrace(this, ApiHttpError);
|
34 | }
|
35 | }
|
36 |
|
37 | util.inherits(ApiHttpError, IdentifiedApiError);
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | function ApiParseError(parseErrorMessage, response) {
|
49 | this.name = "ApiParseError";
|
50 | this.response = response;
|
51 | this.message = parseErrorMessage;
|
52 |
|
53 | if (Error.captureStackTrace
|
54 | && typeof Error.captureStackTrace === 'function') {
|
55 | Error.captureStackTrace(this, ApiParseError);
|
56 | }
|
57 | }
|
58 |
|
59 | util.inherits(ApiParseError, IdentifiedApiError);
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 | function OAuthError(errorResponse, message) {
|
70 | this.name = "OAuthError";
|
71 | this.message = message || errorResponse.errorMessage;
|
72 | this.code = errorResponse.code;
|
73 | this.response = errorResponse;
|
74 |
|
75 | if (Error.captureStackTrace
|
76 | && typeof Error.captureStackTrace === 'function') {
|
77 | Error.captureStackTrace(this, OAuthError);
|
78 | }
|
79 | }
|
80 |
|
81 | util.inherits(OAuthError, IdentifiedApiError);
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 | function ApiError(errorResponse, message) {
|
92 | this.name = "ApiError";
|
93 | this.message = message || errorResponse.errorMessage;
|
94 | this.code = errorResponse.code;
|
95 | this.response = errorResponse;
|
96 |
|
97 | if (Error.captureStackTrace
|
98 | && typeof Error.captureStackTrace === 'function') {
|
99 | Error.captureStackTrace(this, ApiError);
|
100 | }
|
101 | }
|
102 |
|
103 | util.inherits(ApiError, IdentifiedApiError);
|
104 |
|
105 | module.exports = {
|
106 | ApiHttpError: ApiHttpError,
|
107 | ApiParseError: ApiParseError,
|
108 | OAuthError: OAuthError,
|
109 | ApiError: ApiError,
|
110 | IdentifiedApiError: IdentifiedApiError
|
111 | };
|