conductor-node 10.0.1 → 10.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -12
- package/dist/package.json +2 -2
- package/dist/src/integrations/qbd/QbdIntegration.d.ts +167 -167
- package/dist/src/integrations/qbd/QbdIntegration.js +167 -167
- package/dist/src/interceptors/errorHandling.js +15 -10
- package/dist/src/utils/error.d.ts +34 -21
- package/dist/src/utils/error.js +35 -23
- package/package.json +2 -2
|
@@ -8,17 +8,22 @@ function addErrorHandlingInterceptors(httpClient) {
|
|
|
8
8
|
// The request was made and the server responded with a status code that
|
|
9
9
|
// falls out of the range of 2xx.
|
|
10
10
|
if (error.response) {
|
|
11
|
+
const headers = { ...error.response.headers };
|
|
11
12
|
const errorData = error.response.data;
|
|
12
|
-
if (
|
|
13
|
-
throw
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
if ((0, error_1.isWellFormedConductorServerError)(errorData)) {
|
|
14
|
+
throw (0, error_1.generateConductorErrorFromType)({
|
|
15
|
+
...errorData.error,
|
|
16
|
+
httpStatusCode: error.response.status,
|
|
17
|
+
headers,
|
|
17
18
|
});
|
|
18
19
|
}
|
|
19
|
-
throw
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
throw new error_1.ConductorInternalError({
|
|
21
|
+
message: "Invalid JSON received from the Conductor API.",
|
|
22
|
+
code: "INVALID_JSON_RESPONSE",
|
|
23
|
+
httpStatusCode: error.status ?? axios_1.HttpStatusCode.InternalServerError,
|
|
24
|
+
// @ts-expect-error -- `error.response.headers` is always an `AxiosHeaders` instance.
|
|
25
|
+
requestId: error.response.headers.get("request-id"),
|
|
26
|
+
headers,
|
|
22
27
|
});
|
|
23
28
|
}
|
|
24
29
|
if (error.code === axios_1.AxiosError.ECONNABORTED) {
|
|
@@ -27,8 +32,8 @@ function addErrorHandlingInterceptors(httpClient) {
|
|
|
27
32
|
message += ` (${error.config.timeout}ms)`;
|
|
28
33
|
}
|
|
29
34
|
throw new error_1.ConductorConnectionError({
|
|
30
|
-
code: error.code,
|
|
31
35
|
message,
|
|
36
|
+
code: error.code,
|
|
32
37
|
httpStatusCode: error.status ?? axios_1.HttpStatusCode.RequestTimeout,
|
|
33
38
|
});
|
|
34
39
|
}
|
|
@@ -36,8 +41,8 @@ function addErrorHandlingInterceptors(httpClient) {
|
|
|
36
41
|
// Conductor API is offline) or an error ocurred when setting up the
|
|
37
42
|
// request (e.g., no network connection).
|
|
38
43
|
throw new error_1.ConductorConnectionError({
|
|
39
|
-
code: error.code ?? "NETWORK_ERROR",
|
|
40
44
|
message: "An error occurred with our connection to Conductor.",
|
|
45
|
+
code: error.code ?? "NETWORK_ERROR",
|
|
41
46
|
httpStatusCode: error.status,
|
|
42
47
|
});
|
|
43
48
|
});
|
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
export declare const DEFAULT_END_USER_MESSAGE = "An internal server error occurred. Please try again later.";
|
|
2
2
|
export interface ConductorErrorOptions {
|
|
3
|
+
readonly message: string;
|
|
4
|
+
readonly endUserMessage?: string;
|
|
3
5
|
readonly type: string;
|
|
4
6
|
readonly code: string;
|
|
5
7
|
readonly httpStatusCode?: number | undefined;
|
|
6
|
-
readonly message: string;
|
|
7
|
-
readonly endUserMessage?: string;
|
|
8
8
|
readonly integrationCode?: string | undefined;
|
|
9
|
+
readonly requestId?: string | undefined;
|
|
10
|
+
readonly headers?: Record<string, string>;
|
|
9
11
|
}
|
|
10
12
|
/**
|
|
11
13
|
* The raw REST error response that Conductor's API returns.
|
|
12
14
|
*/
|
|
13
15
|
export interface ConductorServerError {
|
|
14
16
|
readonly error: {
|
|
17
|
+
readonly message: string;
|
|
18
|
+
readonly endUserMessage: string;
|
|
15
19
|
readonly type: string;
|
|
16
20
|
readonly code: string;
|
|
17
21
|
readonly httpStatusCode: number;
|
|
18
|
-
readonly message: string;
|
|
19
|
-
readonly endUserMessage: string;
|
|
20
22
|
readonly integrationCode?: string;
|
|
23
|
+
readonly requestId?: string;
|
|
21
24
|
};
|
|
22
25
|
}
|
|
23
26
|
export declare function isWellFormedConductorServerError(error: unknown): error is ConductorServerError;
|
|
@@ -26,6 +29,21 @@ export declare function isWellFormedConductorServerError(error: unknown): error
|
|
|
26
29
|
* Specifically for errors that Conductor's API returned.
|
|
27
30
|
*/
|
|
28
31
|
export declare abstract class ConductorError extends Error {
|
|
32
|
+
/**
|
|
33
|
+
* The developer-friendly error message for your logs.
|
|
34
|
+
*/
|
|
35
|
+
readonly message: string;
|
|
36
|
+
/**
|
|
37
|
+
* The end-user-friendly error message to display in your app's UI to your
|
|
38
|
+
* end-users.
|
|
39
|
+
*
|
|
40
|
+
* This value exists for *every* error. E.g., for a QBD connection error, it
|
|
41
|
+
* might recommend the end-user to check that their QuickBooks Desktop is open
|
|
42
|
+
* and that they're logged in. But if a Conductor API key is expired, e.g.,
|
|
43
|
+
* this message will just say "An internal server error occurred. Please try
|
|
44
|
+
* again later.".
|
|
45
|
+
*/
|
|
46
|
+
readonly endUserMessage: string;
|
|
29
47
|
/**
|
|
30
48
|
* Categorizes the error.
|
|
31
49
|
*
|
|
@@ -42,25 +60,9 @@ export declare abstract class ConductorError extends Error {
|
|
|
42
60
|
*/
|
|
43
61
|
readonly code: string;
|
|
44
62
|
/**
|
|
45
|
-
* The HTTP status code of the response that included the error.
|
|
46
|
-
* won't need this.
|
|
63
|
+
* The HTTP status code of the response that included the error.
|
|
47
64
|
*/
|
|
48
65
|
readonly httpStatusCode: number | undefined;
|
|
49
|
-
/**
|
|
50
|
-
* The developer-friendly error message for your logs.
|
|
51
|
-
*/
|
|
52
|
-
readonly message: string;
|
|
53
|
-
/**
|
|
54
|
-
* The end-user-friendly error message to display in your app's UI to your
|
|
55
|
-
* end-users.
|
|
56
|
-
*
|
|
57
|
-
* This value exists for *every* error. E.g., for a QBD connection error, it
|
|
58
|
-
* might recommend the end-user to check that their QuickBooks Desktop is open
|
|
59
|
-
* and that they're logged in. But if a Conductor API key is expired, e.g.,
|
|
60
|
-
* this message will just say "An internal server error occurred. Please try
|
|
61
|
-
* again later.".
|
|
62
|
-
*/
|
|
63
|
-
readonly endUserMessage: string;
|
|
64
66
|
/**
|
|
65
67
|
* The unique error code supplied by the third-party integration for errors
|
|
66
68
|
* returned by the integration (i.e., `ConductorIntegrationError`) or
|
|
@@ -75,6 +77,17 @@ export declare abstract class ConductorError extends Error {
|
|
|
75
77
|
* should not rely on this code to be the same across integrations.
|
|
76
78
|
*/
|
|
77
79
|
readonly integrationCode: string | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* The unique request identifier of the API request that caused the error.
|
|
82
|
+
*
|
|
83
|
+
* If you need to contact us about a specific request, providing the request
|
|
84
|
+
* identifier will ensure the fastest possible resolution.
|
|
85
|
+
*/
|
|
86
|
+
readonly requestId: string | undefined;
|
|
87
|
+
/**
|
|
88
|
+
* The HTTP headers of the response that included the error.
|
|
89
|
+
*/
|
|
90
|
+
readonly headers: Record<string, string> | undefined;
|
|
78
91
|
/**
|
|
79
92
|
* The internal representation of `type` for debugging.
|
|
80
93
|
*/
|
package/dist/src/utils/error.js
CHANGED
|
@@ -7,11 +7,11 @@ exports.DEFAULT_END_USER_MESSAGE = "An internal server error occurred. Please tr
|
|
|
7
7
|
function isWellFormedConductorServerError(error) {
|
|
8
8
|
return (error instanceof Object &&
|
|
9
9
|
typeof error.error === "object" &&
|
|
10
|
+
typeof error.error.message === "string" &&
|
|
11
|
+
typeof error.error.endUserMessage === "string" &&
|
|
10
12
|
typeof error.error.type === "string" &&
|
|
11
13
|
typeof error.error.code === "string" &&
|
|
12
|
-
typeof error.error.httpStatusCode === "number"
|
|
13
|
-
typeof error.error.message === "string" &&
|
|
14
|
-
typeof error.error.endUserMessage === "string");
|
|
14
|
+
typeof error.error.httpStatusCode === "number");
|
|
15
15
|
}
|
|
16
16
|
exports.isWellFormedConductorServerError = isWellFormedConductorServerError;
|
|
17
17
|
/**
|
|
@@ -19,6 +19,21 @@ exports.isWellFormedConductorServerError = isWellFormedConductorServerError;
|
|
|
19
19
|
* Specifically for errors that Conductor's API returned.
|
|
20
20
|
*/
|
|
21
21
|
class ConductorError extends Error {
|
|
22
|
+
/**
|
|
23
|
+
* The developer-friendly error message for your logs.
|
|
24
|
+
*/
|
|
25
|
+
message;
|
|
26
|
+
/**
|
|
27
|
+
* The end-user-friendly error message to display in your app's UI to your
|
|
28
|
+
* end-users.
|
|
29
|
+
*
|
|
30
|
+
* This value exists for *every* error. E.g., for a QBD connection error, it
|
|
31
|
+
* might recommend the end-user to check that their QuickBooks Desktop is open
|
|
32
|
+
* and that they're logged in. But if a Conductor API key is expired, e.g.,
|
|
33
|
+
* this message will just say "An internal server error occurred. Please try
|
|
34
|
+
* again later.".
|
|
35
|
+
*/
|
|
36
|
+
endUserMessage;
|
|
22
37
|
/**
|
|
23
38
|
* Categorizes the error.
|
|
24
39
|
*
|
|
@@ -35,25 +50,9 @@ class ConductorError extends Error {
|
|
|
35
50
|
*/
|
|
36
51
|
code;
|
|
37
52
|
/**
|
|
38
|
-
* The HTTP status code of the response that included the error.
|
|
39
|
-
* won't need this.
|
|
53
|
+
* The HTTP status code of the response that included the error.
|
|
40
54
|
*/
|
|
41
55
|
httpStatusCode;
|
|
42
|
-
/**
|
|
43
|
-
* The developer-friendly error message for your logs.
|
|
44
|
-
*/
|
|
45
|
-
message;
|
|
46
|
-
/**
|
|
47
|
-
* The end-user-friendly error message to display in your app's UI to your
|
|
48
|
-
* end-users.
|
|
49
|
-
*
|
|
50
|
-
* This value exists for *every* error. E.g., for a QBD connection error, it
|
|
51
|
-
* might recommend the end-user to check that their QuickBooks Desktop is open
|
|
52
|
-
* and that they're logged in. But if a Conductor API key is expired, e.g.,
|
|
53
|
-
* this message will just say "An internal server error occurred. Please try
|
|
54
|
-
* again later.".
|
|
55
|
-
*/
|
|
56
|
-
endUserMessage;
|
|
57
56
|
/**
|
|
58
57
|
* The unique error code supplied by the third-party integration for errors
|
|
59
58
|
* returned by the integration (i.e., `ConductorIntegrationError`) or
|
|
@@ -68,6 +67,17 @@ class ConductorError extends Error {
|
|
|
68
67
|
* should not rely on this code to be the same across integrations.
|
|
69
68
|
*/
|
|
70
69
|
integrationCode;
|
|
70
|
+
/**
|
|
71
|
+
* The unique request identifier of the API request that caused the error.
|
|
72
|
+
*
|
|
73
|
+
* If you need to contact us about a specific request, providing the request
|
|
74
|
+
* identifier will ensure the fastest possible resolution.
|
|
75
|
+
*/
|
|
76
|
+
requestId;
|
|
77
|
+
/**
|
|
78
|
+
* The HTTP headers of the response that included the error.
|
|
79
|
+
*/
|
|
80
|
+
headers;
|
|
71
81
|
/**
|
|
72
82
|
* The internal representation of `type` for debugging.
|
|
73
83
|
*/
|
|
@@ -86,12 +96,14 @@ class ConductorError extends Error {
|
|
|
86
96
|
// `ConductorError` always have the correct `type` even if they are
|
|
87
97
|
// instantiated with the wrong options.
|
|
88
98
|
this.type = this.constructor.name;
|
|
89
|
-
this.rawType = options.type;
|
|
90
|
-
this.code = options.code;
|
|
91
|
-
this.httpStatusCode = options.httpStatusCode;
|
|
92
99
|
this.message = options.message;
|
|
93
100
|
this.endUserMessage = options.endUserMessage ?? exports.DEFAULT_END_USER_MESSAGE;
|
|
101
|
+
this.code = options.code;
|
|
102
|
+
this.httpStatusCode = options.httpStatusCode;
|
|
94
103
|
this.integrationCode = options.integrationCode;
|
|
104
|
+
this.requestId = options.requestId;
|
|
105
|
+
this.headers = options.headers;
|
|
106
|
+
this.rawType = options.type;
|
|
95
107
|
}
|
|
96
108
|
}
|
|
97
109
|
exports.ConductorError = ConductorError;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "conductor-node",
|
|
3
|
-
"version": "10.0
|
|
3
|
+
"version": "10.1.0",
|
|
4
4
|
"description": "Easily integrate the entire QuickBooks Desktop API using fully-typed async TypeScript",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"node": ">=16"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"axios": "^
|
|
27
|
+
"axios": "^1.4.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"axios-mock-adapter": "^1.21.4",
|