-
Notifications
You must be signed in to change notification settings - Fork 128
/
errors.ts
74 lines (62 loc) · 1.86 KB
/
errors.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import type { IdempotencyRecord } from './persistence/IdempotencyRecord.js';
/**
* Item attempting to be inserted into persistence store already exists and is not expired
*/
class IdempotencyItemAlreadyExistsError extends Error {
public existingRecord?: IdempotencyRecord;
public constructor(message?: string, existingRecord?: IdempotencyRecord) {
super(message);
this.existingRecord = existingRecord;
}
}
/**
* Item does not exist in persistence store
*/
class IdempotencyItemNotFoundError extends Error {}
/**
* Execution with idempotency key is already in progress
*/
class IdempotencyAlreadyInProgressError extends Error {}
/**
* An invalid status was provided
*/
class IdempotencyInvalidStatusError extends Error {}
/**
* Payload does not match stored idempotency record
*/
class IdempotencyValidationError extends Error {
public existingRecord?: IdempotencyRecord;
public constructor(message?: string, existingRecord?: IdempotencyRecord) {
super(message);
this.existingRecord = existingRecord;
}
}
/**
* State is inconsistent across multiple requests to persistence store
*/
class IdempotencyInconsistentStateError extends Error {}
/**
* Unrecoverable error from the data store
*/
class IdempotencyPersistenceLayerError extends Error {
public readonly cause: Error | undefined;
public constructor(message: string, cause: Error) {
const errorMessage = `${message}. This error was caused by: ${cause.message}.`;
super(errorMessage);
this.cause = cause;
}
}
/**
* Payload does not contain an idempotent key
*/
class IdempotencyKeyError extends Error {}
export {
IdempotencyItemAlreadyExistsError,
IdempotencyItemNotFoundError,
IdempotencyAlreadyInProgressError,
IdempotencyInvalidStatusError,
IdempotencyValidationError,
IdempotencyInconsistentStateError,
IdempotencyPersistenceLayerError,
IdempotencyKeyError,
};