sqs-consumer 7.4.0 → 7.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/.github/workflows/cla.yml +1 -1
- package/.github/workflows/coverage.yml +3 -3
- package/.github/workflows/dependency-review.yml +1 -1
- package/.github/workflows/docs.yml +5 -5
- package/.github/workflows/issues-to-projects.yml +1 -1
- package/.github/workflows/stale.yml +1 -1
- package/.github/workflows/test.yml +2 -2
- package/README.md +2 -0
- package/dist/consumer.js +3 -3
- package/dist/errors.d.ts +21 -2
- package/dist/errors.js +33 -2
- package/dist/types.d.ts +1 -1
- package/dist/validation.js +5 -0
- package/package.json +1 -1
- package/src/consumer.ts +14 -3
- package/src/errors.ts +49 -2
- package/src/types.ts +2 -1
- package/src/validation.ts +5 -0
|
@@ -11,7 +11,7 @@ jobs:
|
|
|
11
11
|
steps:
|
|
12
12
|
- name: "CLA Check"
|
|
13
13
|
if: (github.event.comment.body == 'recheck' || github.event.comment.body == 'I have read the CLA Document and I hereby sign the CLA') || github.event_name == 'pull_request_target'
|
|
14
|
-
uses: contributor-assistant/github-action@v2.
|
|
14
|
+
uses: contributor-assistant/github-action@v2.3.1
|
|
15
15
|
env:
|
|
16
16
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
17
17
|
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
|
|
@@ -17,10 +17,10 @@ jobs:
|
|
|
17
17
|
node-version: [18.x]
|
|
18
18
|
|
|
19
19
|
steps:
|
|
20
|
-
- uses: actions/checkout@
|
|
20
|
+
- uses: actions/checkout@v4
|
|
21
21
|
|
|
22
22
|
- name: Use Node.js ${{ matrix.node-version }}
|
|
23
|
-
uses: actions/setup-node@
|
|
23
|
+
uses: actions/setup-node@v4
|
|
24
24
|
with:
|
|
25
25
|
node-version: ${{ matrix.node-version }}
|
|
26
26
|
cache: 'npm'
|
|
@@ -32,7 +32,7 @@ jobs:
|
|
|
32
32
|
run: npm ci
|
|
33
33
|
|
|
34
34
|
- name: Report Coverage
|
|
35
|
-
uses: paambaati/codeclimate-action@
|
|
35
|
+
uses: paambaati/codeclimate-action@v5.0.0
|
|
36
36
|
env:
|
|
37
37
|
CC_TEST_REPORTER_ID: 760097cb88b4c685dce427cf94a8e12a5f082774d06b4f4f5daef839ffc07821
|
|
38
38
|
with:
|
|
@@ -29,10 +29,10 @@ jobs:
|
|
|
29
29
|
runs-on: ubuntu-latest
|
|
30
30
|
steps:
|
|
31
31
|
- name: Checkout
|
|
32
|
-
uses: actions/checkout@
|
|
32
|
+
uses: actions/checkout@v4
|
|
33
33
|
|
|
34
34
|
- name: Setup Node.js
|
|
35
|
-
uses: actions/setup-node@
|
|
35
|
+
uses: actions/setup-node@v4
|
|
36
36
|
with:
|
|
37
37
|
node-version: 18.x
|
|
38
38
|
cache: 'npm'
|
|
@@ -47,13 +47,13 @@ jobs:
|
|
|
47
47
|
run: npm run generate-docs
|
|
48
48
|
|
|
49
49
|
- name: Setup Pages
|
|
50
|
-
uses: actions/configure-pages@
|
|
50
|
+
uses: actions/configure-pages@v3
|
|
51
51
|
|
|
52
52
|
- name: Upload artifact
|
|
53
|
-
uses: actions/upload-pages-artifact@
|
|
53
|
+
uses: actions/upload-pages-artifact@v2
|
|
54
54
|
with:
|
|
55
55
|
path: './public'
|
|
56
56
|
|
|
57
57
|
- name: Deploy to GitHub Pages
|
|
58
58
|
id: deployment
|
|
59
|
-
uses: actions/deploy-pages@
|
|
59
|
+
uses: actions/deploy-pages@v2
|
|
@@ -11,7 +11,7 @@ jobs:
|
|
|
11
11
|
name: Add issue to project
|
|
12
12
|
runs-on: ubuntu-latest
|
|
13
13
|
steps:
|
|
14
|
-
- uses: actions/add-to-project@v0.
|
|
14
|
+
- uses: actions/add-to-project@v0.5.0
|
|
15
15
|
with:
|
|
16
16
|
project-url: https://github.com/orgs/bbc/projects/170
|
|
17
17
|
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
|
|
@@ -7,7 +7,7 @@ jobs:
|
|
|
7
7
|
stale:
|
|
8
8
|
runs-on: ubuntu-latest
|
|
9
9
|
steps:
|
|
10
|
-
- uses: actions/stale@
|
|
10
|
+
- uses: actions/stale@v8
|
|
11
11
|
with:
|
|
12
12
|
stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.'
|
|
13
13
|
stale-pr-message: 'This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.'
|
|
@@ -17,10 +17,10 @@ jobs:
|
|
|
17
17
|
node-version: [18.x, 20.x]
|
|
18
18
|
|
|
19
19
|
steps:
|
|
20
|
-
- uses: actions/checkout@
|
|
20
|
+
- uses: actions/checkout@v4
|
|
21
21
|
|
|
22
22
|
- name: Use Node.js ${{ matrix.node-version }}
|
|
23
|
-
uses: actions/setup-node@
|
|
23
|
+
uses: actions/setup-node@v4
|
|
24
24
|
with:
|
|
25
25
|
node-version: ${{ matrix.node-version }}
|
|
26
26
|
cache: 'npm'
|
package/README.md
CHANGED
|
@@ -129,6 +129,8 @@ Returns the current polling state of the consumer: `true` if it is actively poll
|
|
|
129
129
|
|
|
130
130
|
Updates the provided option with the provided value.
|
|
131
131
|
|
|
132
|
+
Please note that any update of the option `pollingWaitTimeMs` will take effect only on next polling cycle.
|
|
133
|
+
|
|
132
134
|
You can [find out more about this here](https://bbc.github.io/sqs-consumer/classes/Consumer.html#updateOption).
|
|
133
135
|
|
|
134
136
|
### Events
|
package/dist/consumer.js
CHANGED
|
@@ -350,10 +350,10 @@ class Consumer extends emitter_1.TypedEventEmitter {
|
|
|
350
350
|
}
|
|
351
351
|
catch (err) {
|
|
352
352
|
if (err instanceof errors_1.TimeoutError) {
|
|
353
|
-
err
|
|
353
|
+
throw (0, errors_1.toTimeoutError)(err, `Message handler timed out after ${this.handleMessageTimeout}ms: Operation timed out.`);
|
|
354
354
|
}
|
|
355
355
|
else if (err instanceof Error) {
|
|
356
|
-
err
|
|
356
|
+
throw (0, errors_1.toStandardError)(err, `Unexpected message handler failure: ${err.message}`);
|
|
357
357
|
}
|
|
358
358
|
throw err;
|
|
359
359
|
}
|
|
@@ -374,7 +374,7 @@ class Consumer extends emitter_1.TypedEventEmitter {
|
|
|
374
374
|
}
|
|
375
375
|
catch (err) {
|
|
376
376
|
if (err instanceof Error) {
|
|
377
|
-
err
|
|
377
|
+
throw (0, errors_1.toStandardError)(err, `Unexpected message handler failure: ${err.message}`);
|
|
378
378
|
}
|
|
379
379
|
throw err;
|
|
380
380
|
}
|
package/dist/errors.d.ts
CHANGED
|
@@ -9,6 +9,13 @@ declare class SQSError extends Error {
|
|
|
9
9
|
constructor(message: string);
|
|
10
10
|
}
|
|
11
11
|
declare class TimeoutError extends Error {
|
|
12
|
+
cause: Error;
|
|
13
|
+
time: Date;
|
|
14
|
+
constructor(message?: string);
|
|
15
|
+
}
|
|
16
|
+
declare class StandardError extends Error {
|
|
17
|
+
cause: Error;
|
|
18
|
+
time: Date;
|
|
12
19
|
constructor(message?: string);
|
|
13
20
|
}
|
|
14
21
|
/**
|
|
@@ -19,7 +26,19 @@ declare function isConnectionError(err: Error): boolean;
|
|
|
19
26
|
/**
|
|
20
27
|
* Formats an AWSError the the SQSError type.
|
|
21
28
|
* @param err The error object that was received.
|
|
22
|
-
* @param message The message
|
|
29
|
+
* @param message The message to send with the error.
|
|
23
30
|
*/
|
|
24
31
|
declare function toSQSError(err: AWSError, message: string): SQSError;
|
|
25
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Formats an Error to the StandardError type.
|
|
34
|
+
* @param err The error object that was received.
|
|
35
|
+
* @param message The message to send with the error.
|
|
36
|
+
*/
|
|
37
|
+
declare function toStandardError(err: Error, message: string): StandardError;
|
|
38
|
+
/**
|
|
39
|
+
* Formats an Error to the TimeoutError type.
|
|
40
|
+
* @param err The error object that was received.
|
|
41
|
+
* @param message The message to send with the error.
|
|
42
|
+
*/
|
|
43
|
+
declare function toTimeoutError(err: TimeoutError, message: string): TimeoutError;
|
|
44
|
+
export { SQSError, TimeoutError, isConnectionError, toSQSError, toStandardError, toTimeoutError };
|
package/dist/errors.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toSQSError = exports.isConnectionError = exports.TimeoutError = exports.SQSError = void 0;
|
|
3
|
+
exports.toTimeoutError = exports.toStandardError = exports.toSQSError = exports.isConnectionError = exports.TimeoutError = exports.SQSError = void 0;
|
|
4
4
|
class SQSError extends Error {
|
|
5
5
|
constructor(message) {
|
|
6
6
|
super(message);
|
|
@@ -16,6 +16,13 @@ class TimeoutError extends Error {
|
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
exports.TimeoutError = TimeoutError;
|
|
19
|
+
class StandardError extends Error {
|
|
20
|
+
constructor(message = 'An unexpected error occurred:') {
|
|
21
|
+
super(message);
|
|
22
|
+
this.message = message;
|
|
23
|
+
this.name = 'StandardError';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
19
26
|
/**
|
|
20
27
|
* Checks if the error provided should be treated as a connection error.
|
|
21
28
|
* @param err The error that was received.
|
|
@@ -33,7 +40,7 @@ exports.isConnectionError = isConnectionError;
|
|
|
33
40
|
/**
|
|
34
41
|
* Formats an AWSError the the SQSError type.
|
|
35
42
|
* @param err The error object that was received.
|
|
36
|
-
* @param message The message
|
|
43
|
+
* @param message The message to send with the error.
|
|
37
44
|
*/
|
|
38
45
|
function toSQSError(err, message) {
|
|
39
46
|
var _a, _b;
|
|
@@ -47,3 +54,27 @@ function toSQSError(err, message) {
|
|
|
47
54
|
return sqsError;
|
|
48
55
|
}
|
|
49
56
|
exports.toSQSError = toSQSError;
|
|
57
|
+
/**
|
|
58
|
+
* Formats an Error to the StandardError type.
|
|
59
|
+
* @param err The error object that was received.
|
|
60
|
+
* @param message The message to send with the error.
|
|
61
|
+
*/
|
|
62
|
+
function toStandardError(err, message) {
|
|
63
|
+
const error = new StandardError(message);
|
|
64
|
+
error.cause = err;
|
|
65
|
+
error.time = new Date();
|
|
66
|
+
return error;
|
|
67
|
+
}
|
|
68
|
+
exports.toStandardError = toStandardError;
|
|
69
|
+
/**
|
|
70
|
+
* Formats an Error to the TimeoutError type.
|
|
71
|
+
* @param err The error object that was received.
|
|
72
|
+
* @param message The message to send with the error.
|
|
73
|
+
*/
|
|
74
|
+
function toTimeoutError(err, message) {
|
|
75
|
+
const error = new TimeoutError(message);
|
|
76
|
+
error.cause = err;
|
|
77
|
+
error.time = new Date();
|
|
78
|
+
return error;
|
|
79
|
+
}
|
|
80
|
+
exports.toTimeoutError = toTimeoutError;
|
package/dist/types.d.ts
CHANGED
|
@@ -119,7 +119,7 @@ export interface ConsumerOptions {
|
|
|
119
119
|
*/
|
|
120
120
|
postReceiveMessageCallback?(): Promise<void>;
|
|
121
121
|
}
|
|
122
|
-
export type UpdatableOptions = 'visibilityTimeout' | 'batchSize' | 'waitTimeSeconds';
|
|
122
|
+
export type UpdatableOptions = 'visibilityTimeout' | 'batchSize' | 'waitTimeSeconds' | 'pollingWaitTimeMs';
|
|
123
123
|
export interface StopOptions {
|
|
124
124
|
/**
|
|
125
125
|
* Default to `false`, if you want the stop action to also abort requests to SQS
|
package/dist/validation.js
CHANGED
|
@@ -30,6 +30,11 @@ function validateOption(option, value, allOptions, strict) {
|
|
|
30
30
|
throw new Error('waitTimeSeconds must be between 0 and 20.');
|
|
31
31
|
}
|
|
32
32
|
break;
|
|
33
|
+
case 'pollingWaitTimeMs':
|
|
34
|
+
if (value < 0) {
|
|
35
|
+
throw new Error('pollingWaitTimeMs must be greater than 0.');
|
|
36
|
+
}
|
|
37
|
+
break;
|
|
33
38
|
default:
|
|
34
39
|
if (strict) {
|
|
35
40
|
throw new Error(`The update ${option} cannot be updated`);
|
package/package.json
CHANGED
package/src/consumer.ts
CHANGED
|
@@ -22,6 +22,8 @@ import { autoBind } from './bind';
|
|
|
22
22
|
import {
|
|
23
23
|
SQSError,
|
|
24
24
|
TimeoutError,
|
|
25
|
+
toStandardError,
|
|
26
|
+
toTimeoutError,
|
|
25
27
|
toSQSError,
|
|
26
28
|
isConnectionError
|
|
27
29
|
} from './errors';
|
|
@@ -453,9 +455,15 @@ export class Consumer extends TypedEventEmitter {
|
|
|
453
455
|
return result instanceof Object ? result : message;
|
|
454
456
|
} catch (err) {
|
|
455
457
|
if (err instanceof TimeoutError) {
|
|
456
|
-
|
|
458
|
+
throw toTimeoutError(
|
|
459
|
+
err,
|
|
460
|
+
`Message handler timed out after ${this.handleMessageTimeout}ms: Operation timed out.`
|
|
461
|
+
);
|
|
457
462
|
} else if (err instanceof Error) {
|
|
458
|
-
|
|
463
|
+
throw toStandardError(
|
|
464
|
+
err,
|
|
465
|
+
`Unexpected message handler failure: ${err.message}`
|
|
466
|
+
);
|
|
459
467
|
}
|
|
460
468
|
throw err;
|
|
461
469
|
} finally {
|
|
@@ -476,7 +484,10 @@ export class Consumer extends TypedEventEmitter {
|
|
|
476
484
|
return result instanceof Object ? result : messages;
|
|
477
485
|
} catch (err) {
|
|
478
486
|
if (err instanceof Error) {
|
|
479
|
-
|
|
487
|
+
throw toStandardError(
|
|
488
|
+
err,
|
|
489
|
+
`Unexpected message handler failure: ${err.message}`
|
|
490
|
+
);
|
|
480
491
|
}
|
|
481
492
|
throw err;
|
|
482
493
|
}
|
package/src/errors.ts
CHANGED
|
@@ -15,6 +15,9 @@ class SQSError extends Error {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
class TimeoutError extends Error {
|
|
18
|
+
cause: Error;
|
|
19
|
+
time: Date;
|
|
20
|
+
|
|
18
21
|
constructor(message = 'Operation timed out.') {
|
|
19
22
|
super(message);
|
|
20
23
|
this.message = message;
|
|
@@ -22,6 +25,17 @@ class TimeoutError extends Error {
|
|
|
22
25
|
}
|
|
23
26
|
}
|
|
24
27
|
|
|
28
|
+
class StandardError extends Error {
|
|
29
|
+
cause: Error;
|
|
30
|
+
time: Date;
|
|
31
|
+
|
|
32
|
+
constructor(message = 'An unexpected error occurred:') {
|
|
33
|
+
super(message);
|
|
34
|
+
this.message = message;
|
|
35
|
+
this.name = 'StandardError';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
25
39
|
/**
|
|
26
40
|
* Checks if the error provided should be treated as a connection error.
|
|
27
41
|
* @param err The error that was received.
|
|
@@ -41,7 +55,7 @@ function isConnectionError(err: Error): boolean {
|
|
|
41
55
|
/**
|
|
42
56
|
* Formats an AWSError the the SQSError type.
|
|
43
57
|
* @param err The error object that was received.
|
|
44
|
-
* @param message The message
|
|
58
|
+
* @param message The message to send with the error.
|
|
45
59
|
*/
|
|
46
60
|
function toSQSError(err: AWSError, message: string): SQSError {
|
|
47
61
|
const sqsError = new SQSError(message);
|
|
@@ -55,4 +69,37 @@ function toSQSError(err: AWSError, message: string): SQSError {
|
|
|
55
69
|
return sqsError;
|
|
56
70
|
}
|
|
57
71
|
|
|
58
|
-
|
|
72
|
+
/**
|
|
73
|
+
* Formats an Error to the StandardError type.
|
|
74
|
+
* @param err The error object that was received.
|
|
75
|
+
* @param message The message to send with the error.
|
|
76
|
+
*/
|
|
77
|
+
function toStandardError(err: Error, message: string): StandardError {
|
|
78
|
+
const error = new StandardError(message);
|
|
79
|
+
error.cause = err;
|
|
80
|
+
error.time = new Date();
|
|
81
|
+
|
|
82
|
+
return error;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Formats an Error to the TimeoutError type.
|
|
87
|
+
* @param err The error object that was received.
|
|
88
|
+
* @param message The message to send with the error.
|
|
89
|
+
*/
|
|
90
|
+
function toTimeoutError(err: TimeoutError, message: string): TimeoutError {
|
|
91
|
+
const error = new TimeoutError(message);
|
|
92
|
+
error.cause = err;
|
|
93
|
+
error.time = new Date();
|
|
94
|
+
|
|
95
|
+
return error;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export {
|
|
99
|
+
SQSError,
|
|
100
|
+
TimeoutError,
|
|
101
|
+
isConnectionError,
|
|
102
|
+
toSQSError,
|
|
103
|
+
toStandardError,
|
|
104
|
+
toTimeoutError
|
|
105
|
+
};
|
package/src/types.ts
CHANGED
package/src/validation.ts
CHANGED
|
@@ -45,6 +45,11 @@ function validateOption(
|
|
|
45
45
|
throw new Error('waitTimeSeconds must be between 0 and 20.');
|
|
46
46
|
}
|
|
47
47
|
break;
|
|
48
|
+
case 'pollingWaitTimeMs':
|
|
49
|
+
if (value < 0) {
|
|
50
|
+
throw new Error('pollingWaitTimeMs must be greater than 0.');
|
|
51
|
+
}
|
|
52
|
+
break;
|
|
48
53
|
default:
|
|
49
54
|
if (strict) {
|
|
50
55
|
throw new Error(`The update ${option} cannot be updated`);
|