sqs-consumer 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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
- ## [10.0.1](https://github.com/bbc/sqs-consumer/compare/v10.0.0...v10.0.1) (2024-04-27)
1
+ ## [10.1.0](https://github.com/bbc/sqs-consumer/compare/v10.0.1...v10.1.0) (2024-04-27)
2
2
 
3
3
 
4
- ### Chores
4
+ ### Features
5
5
 
6
- * add node 22 tests ([#488](https://github.com/bbc/sqs-consumer/issues/488)) ([494ed94](https://github.com/bbc/sqs-consumer/commit/494ed94e148fd72f578ef13960769708a8500494))
6
+ * extend authentication error to handle more codes ([#489](https://github.com/bbc/sqs-consumer/issues/489)) ([45f0916](https://github.com/bbc/sqs-consumer/commit/45f09163c086784545e41b8c24ee458d6784bbe7))
@@ -178,6 +178,7 @@ class Consumer extends emitter_js_1.TypedEventEmitter {
178
178
  this.emitError(err);
179
179
  if ((0, errors_js_1.isConnectionError)(err)) {
180
180
  logger_js_1.logger.debug("authentication_error", {
181
+ code: err.code || "Unknown",
181
182
  detail: "There was an authentication error. Pausing before retrying.",
182
183
  });
183
184
  currentPollingTimeout = this.authenticationErrorTimeout;
@@ -23,17 +23,27 @@ class StandardError extends Error {
23
23
  this.name = "StandardError";
24
24
  }
25
25
  }
26
+ /**
27
+ * List of SQS error codes that are considered connection errors.
28
+ */
29
+ const CONNECTION_ERRORS = [
30
+ "CredentialsError",
31
+ "UnknownEndpoint",
32
+ "AWS.SimpleQueueService.NonExistentQueue",
33
+ "CredentialsProviderError",
34
+ "InvalidAddress",
35
+ "InvalidSecurity",
36
+ "QueueDoesNotExist",
37
+ "RequestThrottled",
38
+ "OverLimit",
39
+ ];
26
40
  /**
27
41
  * Checks if the error provided should be treated as a connection error.
28
42
  * @param err The error that was received.
29
43
  */
30
44
  function isConnectionError(err) {
31
45
  if (err instanceof SQSError) {
32
- return (err.statusCode === 403 ||
33
- err.code === "CredentialsError" ||
34
- err.code === "UnknownEndpoint" ||
35
- err.code === "AWS.SimpleQueueService.NonExistentQueue" ||
36
- err.code === "CredentialsProviderError");
46
+ return err.statusCode === 403 || CONNECTION_ERRORS.includes(err.code);
37
47
  }
38
48
  return false;
39
49
  }
@@ -175,6 +175,7 @@ export class Consumer extends TypedEventEmitter {
175
175
  this.emitError(err);
176
176
  if (isConnectionError(err)) {
177
177
  logger.debug("authentication_error", {
178
+ code: err.code || "Unknown",
178
179
  detail: "There was an authentication error. Pausing before retrying.",
179
180
  });
180
181
  currentPollingTimeout = this.authenticationErrorTimeout;
@@ -18,17 +18,27 @@ class StandardError extends Error {
18
18
  this.name = "StandardError";
19
19
  }
20
20
  }
21
+ /**
22
+ * List of SQS error codes that are considered connection errors.
23
+ */
24
+ const CONNECTION_ERRORS = [
25
+ "CredentialsError",
26
+ "UnknownEndpoint",
27
+ "AWS.SimpleQueueService.NonExistentQueue",
28
+ "CredentialsProviderError",
29
+ "InvalidAddress",
30
+ "InvalidSecurity",
31
+ "QueueDoesNotExist",
32
+ "RequestThrottled",
33
+ "OverLimit",
34
+ ];
21
35
  /**
22
36
  * Checks if the error provided should be treated as a connection error.
23
37
  * @param err The error that was received.
24
38
  */
25
39
  function isConnectionError(err) {
26
40
  if (err instanceof SQSError) {
27
- return (err.statusCode === 403 ||
28
- err.code === "CredentialsError" ||
29
- err.code === "UnknownEndpoint" ||
30
- err.code === "AWS.SimpleQueueService.NonExistentQueue" ||
31
- err.code === "CredentialsProviderError");
41
+ return err.statusCode === 403 || CONNECTION_ERRORS.includes(err.code);
32
42
  }
33
43
  return false;
34
44
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sqs-consumer",
3
- "version": "10.0.1",
3
+ "version": "10.1.0",
4
4
  "description": "Build SQS-based Node applications without the boilerplate",
5
5
  "type": "module",
6
6
  "exports": {
package/src/consumer.ts CHANGED
@@ -251,6 +251,7 @@ export class Consumer extends TypedEventEmitter {
251
251
  this.emitError(err);
252
252
  if (isConnectionError(err)) {
253
253
  logger.debug("authentication_error", {
254
+ code: err.code || "Unknown",
254
255
  detail:
255
256
  "There was an authentication error. Pausing before retrying.",
256
257
  });
package/src/errors.ts CHANGED
@@ -36,19 +36,28 @@ class StandardError extends Error {
36
36
  }
37
37
  }
38
38
 
39
+ /**
40
+ * List of SQS error codes that are considered connection errors.
41
+ */
42
+ const CONNECTION_ERRORS = [
43
+ "CredentialsError",
44
+ "UnknownEndpoint",
45
+ "AWS.SimpleQueueService.NonExistentQueue",
46
+ "CredentialsProviderError",
47
+ "InvalidAddress",
48
+ "InvalidSecurity",
49
+ "QueueDoesNotExist",
50
+ "RequestThrottled",
51
+ "OverLimit",
52
+ ];
53
+
39
54
  /**
40
55
  * Checks if the error provided should be treated as a connection error.
41
56
  * @param err The error that was received.
42
57
  */
43
58
  function isConnectionError(err: Error): boolean {
44
59
  if (err instanceof SQSError) {
45
- return (
46
- err.statusCode === 403 ||
47
- err.code === "CredentialsError" ||
48
- err.code === "UnknownEndpoint" ||
49
- err.code === "AWS.SimpleQueueService.NonExistentQueue" ||
50
- err.code === "CredentialsProviderError"
51
- );
60
+ return err.statusCode === 403 || CONNECTION_ERRORS.includes(err.code);
52
61
  }
53
62
  return false;
54
63
  }