|
| 1 | +import { EventType } from './constants'; |
| 2 | + |
1 | 3 | /** |
2 | | - * Base error type for batch processing |
3 | | - * All errors thrown by major failures extend this base class |
| 4 | + * Base error thrown by the Batch Processing utility |
4 | 5 | */ |
5 | | -class BaseBatchProcessingError extends Error { |
6 | | - public childErrors: Error[]; |
7 | | - |
8 | | - public msg: string; |
9 | | - |
10 | | - public constructor(msg: string, childErrors: Error[]) { |
11 | | - super(msg); |
12 | | - this.msg = msg; |
13 | | - this.childErrors = childErrors; |
| 6 | +class BatchProcessingError extends Error { |
| 7 | + public constructor(message: string) { |
| 8 | + super(message); |
| 9 | + this.name = 'BatchProcessingError'; |
14 | 10 | } |
| 11 | +} |
15 | 12 |
|
16 | | - /** |
17 | | - * Generates a list of errors that were generated by the major failure |
18 | | - * @returns Formatted string listing all the errors that occurred |
19 | | - * |
20 | | - * @example |
21 | | - * When all batch records fail to be processed, this will generate a string like: |
22 | | - * All records failed processing. 3 individual errors logged separately below. |
23 | | - * ,Failed to process record. |
24 | | - * ,Failed to process record. |
25 | | - * ,Failed to process record. |
26 | | - */ |
27 | | - public formatErrors(parentErrorString: string): string { |
28 | | - const errorList: string[] = [parentErrorString + '\n']; |
29 | | - |
30 | | - for (const error of this.childErrors) { |
31 | | - errorList.push(error.message + '\n'); |
32 | | - } |
| 13 | +/** |
| 14 | + * Error thrown by the Batch Processing utility when all batch records failed to be processed |
| 15 | + */ |
| 16 | +class FullBatchFailureError extends BatchProcessingError { |
| 17 | + public recordErrors: Error[]; |
33 | 18 |
|
34 | | - return '\n' + errorList; |
| 19 | + public constructor(childErrors: Error[]) { |
| 20 | + super('All records failed processing. See individual errors below.'); |
| 21 | + this.recordErrors = childErrors; |
| 22 | + this.name = 'FullBatchFailureError'; |
35 | 23 | } |
36 | 24 | } |
37 | 25 |
|
38 | 26 | /** |
39 | | - * When all batch records failed to be processed |
| 27 | + * Error thrown by the Batch Processing utility when a SQS FIFO queue is short-circuited. |
| 28 | + * This happens when a record fails processing and the remaining records are not processed |
| 29 | + * to avoid out-of-order delivery. |
40 | 30 | */ |
41 | | -class BatchProcessingError extends BaseBatchProcessingError { |
42 | | - public constructor(msg: string, childErrors: Error[]) { |
43 | | - super(msg, childErrors); |
44 | | - const parentErrorString: string = this.message; |
45 | | - this.message = this.formatErrors(parentErrorString); |
| 31 | +class SqsFifoShortCircuitError extends BatchProcessingError { |
| 32 | + public constructor() { |
| 33 | + super( |
| 34 | + 'A previous record failed processing. The remaining records were not processed to avoid out-of-order delivery.' |
| 35 | + ); |
| 36 | + this.name = 'SqsFifoShortCircuitError'; |
46 | 37 | } |
47 | 38 | } |
48 | 39 |
|
49 | | -export { BaseBatchProcessingError, BatchProcessingError }; |
| 40 | +/** |
| 41 | + * Error thrown by the Batch Processing utility when a partial processor receives an unexpected |
| 42 | + * batch type. |
| 43 | + */ |
| 44 | +class UnexpectedBatchTypeError extends BatchProcessingError { |
| 45 | + public constructor() { |
| 46 | + super( |
| 47 | + `Unexpected batch type. Possible values are: ${Object.values( |
| 48 | + EventType |
| 49 | + ).join(', ')}` |
| 50 | + ); |
| 51 | + this.name = 'UnexpectedBatchTypeError'; |
| 52 | + } |
| 53 | +} |
| 54 | +export { |
| 55 | + BatchProcessingError, |
| 56 | + FullBatchFailureError, |
| 57 | + SqsFifoShortCircuitError, |
| 58 | + UnexpectedBatchTypeError, |
| 59 | +}; |
0 commit comments