conductor-node 8.4.0 → 8.5.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 +9 -4
- package/dist/package.json +1 -1
- package/dist/src/errors.d.ts +101 -0
- package/dist/src/errors.js +156 -0
- package/dist/src/graphql/graphqlOperationWrapper.d.ts +1 -1
- package/dist/src/graphql/graphqlOperationWrapper.js +13 -16
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -1
- package/package.json +1 -1
- package/dist/src/error.d.ts +0 -57
- package/dist/src/error.js +0 -99
package/README.md
CHANGED
|
@@ -164,14 +164,19 @@ The `ConductorError` and its subclasses have the following properties:
|
|
|
164
164
|
{
|
|
165
165
|
// The error type.
|
|
166
166
|
type: string;
|
|
167
|
-
// The error code.
|
|
167
|
+
// The unique error code. This is useful for adding special handling
|
|
168
|
+
// for specific errors.
|
|
168
169
|
code: string;
|
|
169
|
-
// The
|
|
170
|
+
// The error message for your logs.
|
|
170
171
|
message: string;
|
|
171
172
|
// The end-user-friendly error message to display in your app.
|
|
172
173
|
endUserMessage: string;
|
|
173
|
-
// The HTTP status code.
|
|
174
|
-
|
|
174
|
+
// The HTTP status code of the response that included the error.
|
|
175
|
+
httpStatusCode: number | undefined;
|
|
176
|
+
// The error code provided by the third-party integration when `type`
|
|
177
|
+
// is `ConductorIntegrationError`. This is useful for adding special
|
|
178
|
+
// handling for specific errors from the third-party integration.
|
|
179
|
+
integrationCode: string | undefined;
|
|
175
180
|
}
|
|
176
181
|
```
|
|
177
182
|
|
package/dist/package.json
CHANGED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
export declare const DEFAULT_END_USER_MESSAGE = "An internal server error occurred. Please try again later.";
|
|
2
|
+
export interface ConductorErrorOptions {
|
|
3
|
+
readonly rawType: string;
|
|
4
|
+
readonly code: string;
|
|
5
|
+
readonly message: string;
|
|
6
|
+
readonly endUserMessage?: string;
|
|
7
|
+
readonly httpStatusCode?: number;
|
|
8
|
+
readonly integrationCode?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The base error from which all other more specific Conductor errors derive.
|
|
12
|
+
* Specifically for errors returned from Conductor's API.
|
|
13
|
+
*/
|
|
14
|
+
export declare class ConductorError extends Error {
|
|
15
|
+
/**
|
|
16
|
+
* The error type.
|
|
17
|
+
*/
|
|
18
|
+
readonly type: string;
|
|
19
|
+
/**
|
|
20
|
+
* The raw error type for internal debugging.
|
|
21
|
+
*/
|
|
22
|
+
readonly rawType: string;
|
|
23
|
+
/**
|
|
24
|
+
* The unique error code. This is useful for adding special handling
|
|
25
|
+
* for specific errors.
|
|
26
|
+
*/
|
|
27
|
+
readonly code: string;
|
|
28
|
+
/**
|
|
29
|
+
* The developer-friendly error message for your logs.
|
|
30
|
+
*
|
|
31
|
+
* (Defined in the base class but documented here for completeness.)
|
|
32
|
+
*/
|
|
33
|
+
/**
|
|
34
|
+
* The end-user-friendly error message to display in your app.
|
|
35
|
+
*/
|
|
36
|
+
readonly endUserMessage: string;
|
|
37
|
+
/**
|
|
38
|
+
* The HTTP status code of the response that included the error.
|
|
39
|
+
*/
|
|
40
|
+
readonly httpStatusCode: number | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* The error code provided by the third-party integration when `type` is
|
|
43
|
+
* `ConductorIntegrationError`. This is useful for adding special handling for
|
|
44
|
+
* specific errors from the third-party integration.
|
|
45
|
+
*
|
|
46
|
+
* The third-party integration's error codes are not standardized, so you
|
|
47
|
+
* should not rely on this code to be the same across integrations.
|
|
48
|
+
*/
|
|
49
|
+
readonly integrationCode: string | undefined;
|
|
50
|
+
protected constructor(options: ConductorErrorOptions);
|
|
51
|
+
}
|
|
52
|
+
type ConductorErrorOptionsWithoutRawType = Omit<ConductorErrorOptions, "rawType">;
|
|
53
|
+
/**
|
|
54
|
+
* Raised when an error occurs on the third-party integration's end while
|
|
55
|
+
* processing your end-user's request. E.g., QBWC failed to connect to
|
|
56
|
+
* QuickBooks Desktop on the end-user's computer.
|
|
57
|
+
*/
|
|
58
|
+
export declare class ConductorIntegrationError extends ConductorError {
|
|
59
|
+
static readonly rawType: string;
|
|
60
|
+
constructor(options: ConductorErrorOptionsWithoutRawType);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Raised when you make an API call with the wrong parameters, in the wrong
|
|
64
|
+
* state, or in an invalid way.
|
|
65
|
+
*/
|
|
66
|
+
export declare class ConductorInvalidRequestError extends ConductorError {
|
|
67
|
+
static readonly rawType = "INVALID_REQUEST_ERROR";
|
|
68
|
+
constructor(options: ConductorErrorOptionsWithoutRawType);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Raised when Conductor cannot authenticate you with the credentials you
|
|
72
|
+
* provided. E.g., an incorrect API key.
|
|
73
|
+
*/
|
|
74
|
+
export declare class ConductorAuthenticationError extends ConductorError {
|
|
75
|
+
static readonly rawType = "AUTHENTICATION_ERROR";
|
|
76
|
+
constructor(options: ConductorErrorOptionsWithoutRawType);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Raised when there is a network problem between the client (on your server)
|
|
80
|
+
* and Conductor's servers. E.g., a downed network or a bad TLS certificate.
|
|
81
|
+
*/
|
|
82
|
+
export declare class ConductorConnectionError extends ConductorError {
|
|
83
|
+
static readonly rawType = "CONNECTION_ERROR";
|
|
84
|
+
constructor(options: ConductorErrorOptionsWithoutRawType);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Raised when something goes wrong on Conductor's end. (These are rare.)
|
|
88
|
+
*/
|
|
89
|
+
export declare class ConductorInternalError extends ConductorError {
|
|
90
|
+
static readonly rawType = "INTERNAL_ERROR";
|
|
91
|
+
constructor(options: ConductorErrorOptionsWithoutRawType);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Raised as a fallback for any other error from Conductor that no other error
|
|
95
|
+
* type captures.
|
|
96
|
+
*/
|
|
97
|
+
export declare class ConductorUnknownError extends ConductorError {
|
|
98
|
+
constructor(options: ConductorErrorOptions);
|
|
99
|
+
}
|
|
100
|
+
export declare function generateConductorErrorFromType(options: ConductorErrorOptions): ConductorError;
|
|
101
|
+
export {};
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateConductorErrorFromType = exports.ConductorUnknownError = exports.ConductorInternalError = exports.ConductorConnectionError = exports.ConductorAuthenticationError = exports.ConductorInvalidRequestError = exports.ConductorIntegrationError = exports.ConductorError = exports.DEFAULT_END_USER_MESSAGE = void 0;
|
|
4
|
+
/* eslint-disable max-classes-per-file -- Use one module for all error classes. */
|
|
5
|
+
exports.DEFAULT_END_USER_MESSAGE = "An internal server error occurred. Please try again later.";
|
|
6
|
+
/**
|
|
7
|
+
* The base error from which all other more specific Conductor errors derive.
|
|
8
|
+
* Specifically for errors returned from Conductor's API.
|
|
9
|
+
*/
|
|
10
|
+
class ConductorError extends Error {
|
|
11
|
+
/**
|
|
12
|
+
* The error type.
|
|
13
|
+
*/
|
|
14
|
+
type;
|
|
15
|
+
/**
|
|
16
|
+
* The raw error type for internal debugging.
|
|
17
|
+
*/
|
|
18
|
+
rawType;
|
|
19
|
+
/**
|
|
20
|
+
* The unique error code. This is useful for adding special handling
|
|
21
|
+
* for specific errors.
|
|
22
|
+
*/
|
|
23
|
+
code;
|
|
24
|
+
/**
|
|
25
|
+
* The developer-friendly error message for your logs.
|
|
26
|
+
*
|
|
27
|
+
* (Defined in the base class but documented here for completeness.)
|
|
28
|
+
*/
|
|
29
|
+
// public readonly message: string;
|
|
30
|
+
/**
|
|
31
|
+
* The end-user-friendly error message to display in your app.
|
|
32
|
+
*/
|
|
33
|
+
endUserMessage;
|
|
34
|
+
/**
|
|
35
|
+
* The HTTP status code of the response that included the error.
|
|
36
|
+
*/
|
|
37
|
+
httpStatusCode;
|
|
38
|
+
/**
|
|
39
|
+
* The error code provided by the third-party integration when `type` is
|
|
40
|
+
* `ConductorIntegrationError`. This is useful for adding special handling for
|
|
41
|
+
* specific errors from the third-party integration.
|
|
42
|
+
*
|
|
43
|
+
* The third-party integration's error codes are not standardized, so you
|
|
44
|
+
* should not rely on this code to be the same across integrations.
|
|
45
|
+
*/
|
|
46
|
+
integrationCode;
|
|
47
|
+
constructor(options) {
|
|
48
|
+
super(options.message);
|
|
49
|
+
// Set `name` to the constructor name so that the error appears in logs as
|
|
50
|
+
// `[ConductorError: foo]` instead of `[Error: foo]`.
|
|
51
|
+
this.name = this.constructor.name;
|
|
52
|
+
// 1. Set `type`, even though it's redundant with `name`, because `name`
|
|
53
|
+
// does not appear when doing `console.log(error)` unlike all other
|
|
54
|
+
// properties we set.
|
|
55
|
+
// 2. Set `type` to the constructor name to ensure that subclasses of
|
|
56
|
+
// `ConductorError` always have the correct `type` even if they are
|
|
57
|
+
// instantiated with the wrong options.
|
|
58
|
+
this.type = this.constructor.name;
|
|
59
|
+
this.rawType = options.rawType;
|
|
60
|
+
this.code = options.code;
|
|
61
|
+
this.endUserMessage = options.endUserMessage ?? exports.DEFAULT_END_USER_MESSAGE;
|
|
62
|
+
this.httpStatusCode = options.httpStatusCode;
|
|
63
|
+
this.integrationCode = options.integrationCode;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.ConductorError = ConductorError;
|
|
67
|
+
/**
|
|
68
|
+
* Raised when an error occurs on the third-party integration's end while
|
|
69
|
+
* processing your end-user's request. E.g., QBWC failed to connect to
|
|
70
|
+
* QuickBooks Desktop on the end-user's computer.
|
|
71
|
+
*/
|
|
72
|
+
class ConductorIntegrationError extends ConductorError {
|
|
73
|
+
static rawType = "INTEGRATION_ERROR";
|
|
74
|
+
constructor(options) {
|
|
75
|
+
super({ ...options, rawType: ConductorIntegrationError.rawType });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.ConductorIntegrationError = ConductorIntegrationError;
|
|
79
|
+
/**
|
|
80
|
+
* Raised when you make an API call with the wrong parameters, in the wrong
|
|
81
|
+
* state, or in an invalid way.
|
|
82
|
+
*/
|
|
83
|
+
class ConductorInvalidRequestError extends ConductorError {
|
|
84
|
+
static rawType = "INVALID_REQUEST_ERROR";
|
|
85
|
+
constructor(options) {
|
|
86
|
+
super({ ...options, rawType: ConductorInvalidRequestError.rawType });
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
exports.ConductorInvalidRequestError = ConductorInvalidRequestError;
|
|
90
|
+
/**
|
|
91
|
+
* Raised when Conductor cannot authenticate you with the credentials you
|
|
92
|
+
* provided. E.g., an incorrect API key.
|
|
93
|
+
*/
|
|
94
|
+
class ConductorAuthenticationError extends ConductorError {
|
|
95
|
+
static rawType = "AUTHENTICATION_ERROR";
|
|
96
|
+
constructor(options) {
|
|
97
|
+
super({ ...options, rawType: ConductorAuthenticationError.rawType });
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.ConductorAuthenticationError = ConductorAuthenticationError;
|
|
101
|
+
/**
|
|
102
|
+
* Raised when there is a network problem between the client (on your server)
|
|
103
|
+
* and Conductor's servers. E.g., a downed network or a bad TLS certificate.
|
|
104
|
+
*/
|
|
105
|
+
class ConductorConnectionError extends ConductorError {
|
|
106
|
+
static rawType = "CONNECTION_ERROR";
|
|
107
|
+
constructor(options) {
|
|
108
|
+
super({ ...options, rawType: ConductorConnectionError.rawType });
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
exports.ConductorConnectionError = ConductorConnectionError;
|
|
112
|
+
/**
|
|
113
|
+
* Raised when something goes wrong on Conductor's end. (These are rare.)
|
|
114
|
+
*/
|
|
115
|
+
class ConductorInternalError extends ConductorError {
|
|
116
|
+
static rawType = "INTERNAL_ERROR";
|
|
117
|
+
constructor(options) {
|
|
118
|
+
super({ ...options, rawType: ConductorInternalError.rawType });
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exports.ConductorInternalError = ConductorInternalError;
|
|
122
|
+
/**
|
|
123
|
+
* Raised as a fallback for any other error from Conductor that no other error
|
|
124
|
+
* type captures.
|
|
125
|
+
*/
|
|
126
|
+
class ConductorUnknownError extends ConductorError {
|
|
127
|
+
// Override the `protected` constructor in the base class even though we are
|
|
128
|
+
// not overriding `rawType`.
|
|
129
|
+
constructor(options) {
|
|
130
|
+
super(options);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
exports.ConductorUnknownError = ConductorUnknownError;
|
|
134
|
+
function generateConductorErrorFromType(options) {
|
|
135
|
+
switch (options.rawType) {
|
|
136
|
+
case ConductorIntegrationError.rawType: {
|
|
137
|
+
return new ConductorIntegrationError(options);
|
|
138
|
+
}
|
|
139
|
+
case ConductorInvalidRequestError.rawType: {
|
|
140
|
+
return new ConductorInvalidRequestError(options);
|
|
141
|
+
}
|
|
142
|
+
case ConductorAuthenticationError.rawType: {
|
|
143
|
+
return new ConductorAuthenticationError(options);
|
|
144
|
+
}
|
|
145
|
+
case ConductorConnectionError.rawType: {
|
|
146
|
+
return new ConductorConnectionError(options);
|
|
147
|
+
}
|
|
148
|
+
case ConductorInternalError.rawType: {
|
|
149
|
+
return new ConductorInternalError(options);
|
|
150
|
+
}
|
|
151
|
+
default: {
|
|
152
|
+
return new ConductorUnknownError(options);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
exports.generateConductorErrorFromType = generateConductorErrorFromType;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ConductorError } from "../
|
|
1
|
+
import type { ConductorError } from "../errors";
|
|
2
2
|
import type { getSdk } from "../graphql/__generated__/operationTypes";
|
|
3
3
|
export declare function wrapGraphqlOperations<T extends ReturnType<typeof getSdk>>(graphqlOperations: T, verbose: boolean): T;
|
|
4
4
|
export declare function graphqlOperationWrapper<V extends {
|
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.wrapError = exports.graphqlOperationWrapper = exports.wrapGraphqlOperations = void 0;
|
|
7
7
|
const package_json_1 = __importDefault(require("../../package.json"));
|
|
8
|
-
const
|
|
8
|
+
const errors_1 = require("../errors");
|
|
9
9
|
const graphql_request_1 = require("graphql-request");
|
|
10
10
|
const node_util_1 = __importDefault(require("node:util"));
|
|
11
11
|
function wrapGraphqlOperations(graphqlOperations, verbose) {
|
|
@@ -59,45 +59,42 @@ async function graphqlOperationWrapper(operationName, variables, operation, verb
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
exports.graphqlOperationWrapper = graphqlOperationWrapper;
|
|
62
|
+
function getDurationString(startTime) {
|
|
63
|
+
const duration = Date.now() - startTime;
|
|
64
|
+
return `${Math.round(duration / 10) / 100}s`;
|
|
65
|
+
}
|
|
62
66
|
function wrapError(error) {
|
|
63
67
|
if (error instanceof graphql_request_1.ClientError) {
|
|
64
68
|
const { response } = error;
|
|
65
69
|
if ([404, 502, 503].includes(response.status)) {
|
|
66
|
-
return
|
|
67
|
-
type: "CONNECTION_ERROR",
|
|
70
|
+
return new errors_1.ConductorConnectionError({
|
|
68
71
|
code: "SERVER_UNAVAILABLE",
|
|
69
72
|
message: `The Conductor server returned a ${response.status} error, which may indicate that the server is unavailable. Please alert the Conductor team if this error persists.`,
|
|
70
|
-
|
|
73
|
+
httpStatusCode: response.status,
|
|
71
74
|
});
|
|
72
75
|
}
|
|
73
76
|
const nestedError = response.errors?.[0];
|
|
74
77
|
const errorExtensions = nestedError?.extensions;
|
|
75
78
|
if (errorExtensions) {
|
|
76
79
|
if (errorExtensions["code"] === "GRAPHQL_VALIDATION_FAILED") {
|
|
77
|
-
return
|
|
78
|
-
type: "INVALID_REQUEST_ERROR",
|
|
80
|
+
return new errors_1.ConductorInvalidRequestError({
|
|
79
81
|
code: "CLIENT_OUTDATED",
|
|
80
82
|
message: `Your version of "${package_json_1.default.name}" is not longer compatible with the Conductor server. Please run "yarn upgrade ${package_json_1.default.name} --latest" to update.`,
|
|
81
|
-
|
|
83
|
+
httpStatusCode: response.status,
|
|
82
84
|
});
|
|
83
85
|
}
|
|
84
|
-
return (0,
|
|
85
|
-
|
|
86
|
+
return (0, errors_1.generateConductorErrorFromType)({
|
|
87
|
+
rawType: errorExtensions["type"],
|
|
86
88
|
code: errorExtensions["code"],
|
|
87
89
|
message: nestedError.message,
|
|
88
90
|
endUserMessage: errorExtensions["endUserMessage"],
|
|
89
|
-
|
|
91
|
+
httpStatusCode: response.status,
|
|
90
92
|
});
|
|
91
93
|
}
|
|
92
94
|
}
|
|
93
|
-
return
|
|
94
|
-
type: "INTERNAL_ERROR",
|
|
95
|
+
return new errors_1.ConductorInternalError({
|
|
95
96
|
code: "INVALID_JSON_RESPONSE",
|
|
96
97
|
message: "Invalid JSON received from the Conductor API.",
|
|
97
98
|
});
|
|
98
99
|
}
|
|
99
100
|
exports.wrapError = wrapError;
|
|
100
|
-
function getDurationString(startTime) {
|
|
101
|
-
const duration = Date.now() - startTime;
|
|
102
|
-
return `${Math.round(duration / 10) / 100}s`;
|
|
103
|
-
}
|
package/dist/src/index.d.ts
CHANGED
package/dist/src/index.js
CHANGED
|
@@ -34,5 +34,5 @@ exports.QbdTypes = void 0;
|
|
|
34
34
|
const Client_1 = __importDefault(require("./Client"));
|
|
35
35
|
// eslint-disable-next-line unicorn/prefer-export-from -- We need `Client` to be the default export, which is impossible to define with `export from`.
|
|
36
36
|
exports.default = Client_1.default;
|
|
37
|
-
__exportStar(require("./
|
|
37
|
+
__exportStar(require("./errors"), exports);
|
|
38
38
|
exports.QbdTypes = __importStar(require("./integrations/qbd/qbdTypes"));
|
package/package.json
CHANGED
package/dist/src/error.d.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
export declare const DEFAULT_END_USER_MESSAGE = "An internal server error occurred. Please try again later.";
|
|
2
|
-
export interface ConductorErrorOptions {
|
|
3
|
-
readonly type: string;
|
|
4
|
-
readonly code: string;
|
|
5
|
-
readonly message: string;
|
|
6
|
-
readonly endUserMessage?: string;
|
|
7
|
-
readonly statusCode?: number;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* The base error from which all other more specific Conductor errors derive.
|
|
11
|
-
* Specifically for errors returned from Conductor's API.
|
|
12
|
-
*/
|
|
13
|
-
export declare class ConductorError extends Error {
|
|
14
|
-
readonly type: string;
|
|
15
|
-
readonly rawType: string;
|
|
16
|
-
readonly code: string;
|
|
17
|
-
readonly endUserMessage: string;
|
|
18
|
-
readonly statusCode: number | undefined;
|
|
19
|
-
constructor(options: ConductorErrorOptions);
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Raised when an error occurs on the third-party integration's end while
|
|
23
|
-
* processing your end-user's request. E.g., QBWC failed to connect to
|
|
24
|
-
* QuickBooks Desktop on the end-user's computer.
|
|
25
|
-
*/
|
|
26
|
-
export declare class ConductorIntegrationError extends ConductorError {
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Raised when you make an API call with the wrong parameters, in the wrong
|
|
30
|
-
* state, or in an invalid way.
|
|
31
|
-
*/
|
|
32
|
-
export declare class ConductorInvalidRequestError extends ConductorError {
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Raised when Conductor cannot authenticate you with the credentials you
|
|
36
|
-
* provided. E.g., an incorrect API key.
|
|
37
|
-
*/
|
|
38
|
-
export declare class ConductorAuthenticationError extends ConductorError {
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Raised when there is a network problem between the client (on your server)
|
|
42
|
-
* and Conductor's servers. E.g., a downed network or a bad TLS certificate.
|
|
43
|
-
*/
|
|
44
|
-
export declare class ConductorConnectionError extends ConductorError {
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Raised when something goes wrong on Conductor's end. (These are rare.)
|
|
48
|
-
*/
|
|
49
|
-
export declare class ConductorInternalError extends ConductorError {
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Raised as a fallback for any other error from Conductor that no other error
|
|
53
|
-
* type captures.
|
|
54
|
-
*/
|
|
55
|
-
export declare class ConductorUnknownError extends ConductorError {
|
|
56
|
-
}
|
|
57
|
-
export declare function generateConductorError(rawConductorError: ConductorErrorOptions): ConductorError;
|
package/dist/src/error.js
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateConductorError = exports.ConductorUnknownError = exports.ConductorInternalError = exports.ConductorConnectionError = exports.ConductorAuthenticationError = exports.ConductorInvalidRequestError = exports.ConductorIntegrationError = exports.ConductorError = exports.DEFAULT_END_USER_MESSAGE = void 0;
|
|
4
|
-
/* eslint-disable max-classes-per-file -- Keep the error classes together */
|
|
5
|
-
exports.DEFAULT_END_USER_MESSAGE = "An internal server error occurred. Please try again later.";
|
|
6
|
-
/**
|
|
7
|
-
* The base error from which all other more specific Conductor errors derive.
|
|
8
|
-
* Specifically for errors returned from Conductor's API.
|
|
9
|
-
*/
|
|
10
|
-
class ConductorError extends Error {
|
|
11
|
-
type;
|
|
12
|
-
rawType;
|
|
13
|
-
code;
|
|
14
|
-
endUserMessage;
|
|
15
|
-
statusCode;
|
|
16
|
-
constructor(options) {
|
|
17
|
-
super(options.message);
|
|
18
|
-
// Set `name` to the constructor name so that the error appears in logs as
|
|
19
|
-
// `[ConductorError: foo]` instead of `[Error: foo]`.
|
|
20
|
-
this.name = this.constructor.name;
|
|
21
|
-
// 1. Set `type`, even though it's redundant with `name`, because `name`
|
|
22
|
-
// does not appear when doing `console.log(error)` unlike all other
|
|
23
|
-
// properties we set.
|
|
24
|
-
// 2. Set `type` to the constructor name to ensure that subclasses of
|
|
25
|
-
// `ConductorError` always have the correct `type` even if they are
|
|
26
|
-
// instantiated with the wrong options.
|
|
27
|
-
this.type = this.constructor.name;
|
|
28
|
-
this.rawType = options.type;
|
|
29
|
-
this.code = options.code;
|
|
30
|
-
this.endUserMessage = options.endUserMessage ?? exports.DEFAULT_END_USER_MESSAGE;
|
|
31
|
-
this.statusCode = options.statusCode;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
exports.ConductorError = ConductorError;
|
|
35
|
-
/**
|
|
36
|
-
* Raised when an error occurs on the third-party integration's end while
|
|
37
|
-
* processing your end-user's request. E.g., QBWC failed to connect to
|
|
38
|
-
* QuickBooks Desktop on the end-user's computer.
|
|
39
|
-
*/
|
|
40
|
-
class ConductorIntegrationError extends ConductorError {
|
|
41
|
-
}
|
|
42
|
-
exports.ConductorIntegrationError = ConductorIntegrationError;
|
|
43
|
-
/**
|
|
44
|
-
* Raised when you make an API call with the wrong parameters, in the wrong
|
|
45
|
-
* state, or in an invalid way.
|
|
46
|
-
*/
|
|
47
|
-
class ConductorInvalidRequestError extends ConductorError {
|
|
48
|
-
}
|
|
49
|
-
exports.ConductorInvalidRequestError = ConductorInvalidRequestError;
|
|
50
|
-
/**
|
|
51
|
-
* Raised when Conductor cannot authenticate you with the credentials you
|
|
52
|
-
* provided. E.g., an incorrect API key.
|
|
53
|
-
*/
|
|
54
|
-
class ConductorAuthenticationError extends ConductorError {
|
|
55
|
-
}
|
|
56
|
-
exports.ConductorAuthenticationError = ConductorAuthenticationError;
|
|
57
|
-
/**
|
|
58
|
-
* Raised when there is a network problem between the client (on your server)
|
|
59
|
-
* and Conductor's servers. E.g., a downed network or a bad TLS certificate.
|
|
60
|
-
*/
|
|
61
|
-
class ConductorConnectionError extends ConductorError {
|
|
62
|
-
}
|
|
63
|
-
exports.ConductorConnectionError = ConductorConnectionError;
|
|
64
|
-
/**
|
|
65
|
-
* Raised when something goes wrong on Conductor's end. (These are rare.)
|
|
66
|
-
*/
|
|
67
|
-
class ConductorInternalError extends ConductorError {
|
|
68
|
-
}
|
|
69
|
-
exports.ConductorInternalError = ConductorInternalError;
|
|
70
|
-
/**
|
|
71
|
-
* Raised as a fallback for any other error from Conductor that no other error
|
|
72
|
-
* type captures.
|
|
73
|
-
*/
|
|
74
|
-
class ConductorUnknownError extends ConductorError {
|
|
75
|
-
}
|
|
76
|
-
exports.ConductorUnknownError = ConductorUnknownError;
|
|
77
|
-
function generateConductorError(rawConductorError) {
|
|
78
|
-
switch (rawConductorError.type) {
|
|
79
|
-
case "INTEGRATION_ERROR": {
|
|
80
|
-
return new ConductorIntegrationError(rawConductorError);
|
|
81
|
-
}
|
|
82
|
-
case "INVALID_REQUEST_ERROR": {
|
|
83
|
-
return new ConductorInvalidRequestError(rawConductorError);
|
|
84
|
-
}
|
|
85
|
-
case "AUTHENTICATION_ERROR": {
|
|
86
|
-
return new ConductorAuthenticationError(rawConductorError);
|
|
87
|
-
}
|
|
88
|
-
case "CONNECTION_ERROR": {
|
|
89
|
-
return new ConductorConnectionError(rawConductorError);
|
|
90
|
-
}
|
|
91
|
-
case "INTERNAL_ERROR": {
|
|
92
|
-
return new ConductorInternalError(rawConductorError);
|
|
93
|
-
}
|
|
94
|
-
default: {
|
|
95
|
-
return new ConductorUnknownError(rawConductorError);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
exports.generateConductorError = generateConductorError;
|