conductor-node 8.6.1 → 8.6.2

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 CHANGED
@@ -171,12 +171,12 @@ The `ConductorError` and its subclasses have the following properties:
171
171
  message: string;
172
172
  // The end-user-friendly error message to display in your app.
173
173
  endUserMessage: string;
174
- // The HTTP status code of the response that included the error.
175
- httpStatusCode: number | undefined;
176
174
  // The error code provided by the third-party integration when `type`
177
175
  // is `ConductorIntegrationError`. This is useful for adding special
178
176
  // handling for specific errors from the third-party integration.
179
177
  integrationCode: string | undefined;
178
+ // The HTTP status code of the response that included the error.
179
+ httpStatusCode: number | undefined;
180
180
  }
181
181
  ```
182
182
 
@@ -192,7 +192,9 @@ The error object you receive will have one of the following error types:
192
192
  | `ConductorConnectionError` | There was a network problem between the client (on your server) and Conductor's servers. |
193
193
  | `ConductorInternalError` | Something went wrong on Conductor's end. (These are rare.) |
194
194
 
195
- ### Example
195
+ ### Special Handling
196
+
197
+ If you need special handling for specific errors, you can wrap individual API calls as shown below.
196
198
 
197
199
  In the form of a rejected promise:
198
200
 
@@ -208,7 +210,7 @@ conductor.qbd.account
208
210
  })
209
211
  .catch((error) => {
210
212
  if (error instanceof ConductorError) {
211
- // Update your app's UI to display `error.endUserMessage`.
213
+ // Check `error.code`, `error.integrationCode`, etc., for special handling.
212
214
  } else {
213
215
  // ...
214
216
  }
@@ -226,27 +228,28 @@ try {
226
228
  });
227
229
  } catch (error) {
228
230
  if (error instanceof ConductorError) {
229
- // Update your app's UI to display `error.endUserMessage`.
231
+ // Check `error.code`, `error.integrationCode`, etc., for special handling.
230
232
  } else {
231
233
  // ...
232
234
  }
233
235
  }
234
236
  ```
235
237
 
236
- ### Integration
237
-
238
- **NOTE:** We do not expect you to individually wrap every API call like the examples above. Instead, you should only need to wrap a specific Conductor API request when adding special handling for specific errors, such as checking the property `error.code`.
238
+ ### Global Error Handling
239
239
 
240
- Ideally, if your server does not already, we expect you to have a single global error handler, such as [`app.use((error, req, res, next) => { ... })` in Express](https://expressjs.com/en/guide/error-handling.html#writing-error-handlers), or [`formatError` in Apollo Server](https://apollographql.com/docs/apollo-server/data/errors/#for-client-responses). In such a handler, you can do the following:
240
+ We do not expect you to individually wrap every API call like the examples above. Instead, if your server does not already, we expect you to have a single global error handler, such as [`app.use((error, req, res, next) => { ... })` in Express](https://expressjs.com/en/guide/error-handling.html#writing-error-handlers) or [`formatError` in Apollo Server](https://apollographql.com/docs/apollo-server/data/errors/#for-client-responses), where you can do the following:
241
241
 
242
242
  1. Ensure your app's UI shows your end-user the property `error.endUserMessage` of any `ConductorError` instance for any Conductor request while you log the rest.
243
243
  2. Send the full error object to your error-tracking service (e.g., Sentry) for all `ConductorError` instances, for which we recommend:
244
- 1. Send a **warning** to your error-tracking service for instances of `ConductorIntegrationError`, which are your end-user's fault; e.g., cannot connect to QBD on your end-user's computer.
245
- 2. Send an **error** for all other `ConductorError` instances; e.g., invalid API key.
244
+ - Send a **warning** to your error-tracking service for instances of `ConductorIntegrationError`, which are your end-user's fault; e.g., cannot connect to QBD on your end-user's computer.
245
+ - Send an **error** for all other `ConductorError` instances; e.g., invalid API key.
246
246
 
247
- For example, here is how you might do this in Express:
247
+ For example, here is how you can do this with Express:
248
248
 
249
249
  ```ts
250
+ import * as Sentry from "@sentry/node";
251
+ import { ConductorError, ConductorIntegrationError } from "conductor-node";
252
+ // ...
250
253
  app.use((error, req, res, next) => {
251
254
  if (error instanceof ConductorError) {
252
255
  Sentry.captureException(error, {
@@ -260,14 +263,16 @@ app.use((error, req, res, next) => {
260
263
  });
261
264
  ```
262
265
 
263
- And here is how you might do this in Apollo Server:
266
+ And here is how you can do this with Apollo Server:
264
267
 
265
268
  ```ts
269
+ import { ApolloServer } from "@apollo/server";
266
270
  import { unwrapResolverError } from "@apollo/server/errors";
267
-
271
+ import * as Sentry from "@sentry/node";
272
+ import { ConductorError, ConductorIntegrationError } from "conductor-node";
273
+ // ...
268
274
  const server = new ApolloServer({
269
- typeDefs,
270
- resolvers,
275
+ // ...
271
276
  formatError: (formattedError, error) => {
272
277
  const origError = unwrapResolverError(error);
273
278
  if (origError instanceof ConductorError) {
@@ -275,17 +280,14 @@ const server = new ApolloServer({
275
280
  level:
276
281
  origError instanceof ConductorIntegrationError ? "warning" : "error",
277
282
  });
278
- // Return a different error message for your end-user to see in your app's UI.
279
283
  return {
280
284
  ...formattedError,
285
+ // Return a different error message for your end-user to see in
286
+ // your app's UI.
281
287
  message: origError.endUserMessage,
282
288
  };
283
- } else {
284
- // ...
285
289
  }
286
-
287
- // Otherwise return the formatted error. This error can also
288
- // be manipulated in other ways, as long as it's returned.
290
+ // ...
289
291
  return formattedError;
290
292
  },
291
293
  });
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "conductor-node",
3
- "version": "8.6.1",
3
+ "version": "8.6.2",
4
4
  "description": "Easily integrate with the entire QuickBooks Desktop API with fully-typed async TypeScript",
5
5
  "author": "Danny Nemer <hi@DannyNemer.com>",
6
6
  "license": "MIT",
@@ -4,8 +4,8 @@ export interface ConductorErrorOptions {
4
4
  readonly code: string;
5
5
  readonly message: string;
6
6
  readonly endUserMessage?: string;
7
- readonly httpStatusCode?: number;
8
7
  readonly integrationCode?: string;
8
+ readonly httpStatusCode?: number;
9
9
  }
10
10
  /**
11
11
  * The raw GraphQL error that Conductor's API returns.
@@ -41,10 +41,6 @@ export declare class ConductorError extends Error {
41
41
  * The end-user-friendly error message to display in your app.
42
42
  */
43
43
  readonly endUserMessage: string;
44
- /**
45
- * The HTTP status code of the response that included the error.
46
- */
47
- readonly httpStatusCode: number | undefined;
48
44
  /**
49
45
  * The error code provided by the third-party integration when `type` is
50
46
  * `ConductorIntegrationError`. This is useful for adding special handling for
@@ -54,6 +50,10 @@ export declare class ConductorError extends Error {
54
50
  * should not rely on this code to be the same across integrations.
55
51
  */
56
52
  readonly integrationCode: string | undefined;
53
+ /**
54
+ * The HTTP status code of the response that included the error.
55
+ */
56
+ readonly httpStatusCode: number | undefined;
57
57
  protected constructor(options: ConductorErrorOptions);
58
58
  }
59
59
  type ConductorErrorOptionsWithoutType = Omit<ConductorErrorOptions, "type">;
@@ -31,10 +31,6 @@ class ConductorError extends Error {
31
31
  * The end-user-friendly error message to display in your app.
32
32
  */
33
33
  endUserMessage;
34
- /**
35
- * The HTTP status code of the response that included the error.
36
- */
37
- httpStatusCode;
38
34
  /**
39
35
  * The error code provided by the third-party integration when `type` is
40
36
  * `ConductorIntegrationError`. This is useful for adding special handling for
@@ -44,6 +40,10 @@ class ConductorError extends Error {
44
40
  * should not rely on this code to be the same across integrations.
45
41
  */
46
42
  integrationCode;
43
+ /**
44
+ * The HTTP status code of the response that included the error.
45
+ */
46
+ httpStatusCode;
47
47
  constructor(options) {
48
48
  super(options.message);
49
49
  // Set `name` to the constructor name so that the error appears in logs as
@@ -59,8 +59,8 @@ class ConductorError extends Error {
59
59
  this.rawType = options.type;
60
60
  this.code = options.code;
61
61
  this.endUserMessage = options.endUserMessage ?? exports.DEFAULT_END_USER_MESSAGE;
62
- this.httpStatusCode = options.httpStatusCode;
63
62
  this.integrationCode = options.integrationCode;
63
+ this.httpStatusCode = options.httpStatusCode;
64
64
  }
65
65
  }
66
66
  exports.ConductorError = ConductorError;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "conductor-node",
3
- "version": "8.6.1",
3
+ "version": "8.6.2",
4
4
  "description": "Easily integrate with the entire QuickBooks Desktop API with fully-typed async TypeScript",
5
5
  "author": "Danny Nemer <hi@DannyNemer.com>",
6
6
  "license": "MIT",