@factorearth/recordmiddleware-errorhandler 0.0.1-y.33 → 0.0.1-y.34
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/dist/aws-services/dynamodb/determineRetryableDynamo.d.ts +8 -0
- package/dist/aws-services/dynamodb/determineRetryableDynamo.js +4 -7
- package/dist/aws-services/dynamodb/determineRetryableDynamo.js.map +1 -0
- package/dist/backOff.d.ts +28 -0
- package/dist/backOff.js +26 -87
- package/dist/backOff.js.map +1 -0
- package/dist/delay.d.ts +7 -0
- package/dist/delay.js +3 -6
- package/dist/delay.js.map +1 -0
- package/dist/handler.d.ts +10 -0
- package/dist/handler.js +9 -70
- package/dist/handler.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +4 -19
- package/dist/index.js.map +1 -0
- package/package.json +3 -7
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Given the error from the dynamodb operation, dertermines if we can retry it, based on the information from the dynamodb sdk docs
|
|
3
|
+
* {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Programming.Errors.html}
|
|
4
|
+
* @author Eric Webb <ewebb@factorearth.com>
|
|
5
|
+
* @param err The error thrown by the dynamodb operation
|
|
6
|
+
* @returns Whether or not we can retry the operation
|
|
7
|
+
*/
|
|
8
|
+
export declare function determineRetryableDynamo(err: any): boolean;
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.determineRetryableDynamo = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* Given the error from the dynamodb operation, dertermines if we can retry it, based on the information from the dynamodb sdk docs
|
|
6
3
|
* {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Programming.Errors.html}
|
|
@@ -8,11 +5,11 @@ exports.determineRetryableDynamo = void 0;
|
|
|
8
5
|
* @param err The error thrown by the dynamodb operation
|
|
9
6
|
* @returns Whether or not we can retry the operation
|
|
10
7
|
*/
|
|
11
|
-
function determineRetryableDynamo(err) {
|
|
12
|
-
if (!
|
|
8
|
+
export function determineRetryableDynamo(err) {
|
|
9
|
+
if (!err?.name)
|
|
13
10
|
return false;
|
|
14
11
|
// The errors from the link I provided that are marked as retryable
|
|
15
|
-
|
|
12
|
+
const retryableErrors = new Set(["ItemCollectionSizeLimitExceededException", "LimitExceededException", "ProvisionedThroughputExceededException", "RequestLimitExceeded", "ThrottlingException"]);
|
|
16
13
|
return retryableErrors.has(err.name) || (err.$metadata && err.$metadata.httpStatusCode && err.$metadata.httpStatusCode >= 500);
|
|
17
14
|
}
|
|
18
|
-
|
|
15
|
+
//# sourceMappingURL=determineRetryableDynamo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"determineRetryableDynamo.js","sourceRoot":"","sources":["../../../lib/aws-services/dynamodb/determineRetryableDynamo.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CAAC,GAAQ;IAChD,IAAI,CAAC,GAAG,EAAE,IAAI;QAAE,OAAO,KAAK,CAAC;IAC7B,mEAAmE;IACnE,MAAM,eAAe,GAAgB,IAAI,GAAG,CAAC,CAAC,0CAA0C,EAAE,wBAAwB,EAAE,wCAAwC,EAAE,sBAAsB,EAAE,qBAAqB,CAAC,CAAC,CAAC;IAC9M,OAAO,eAAe,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,IAAI,GAAG,CAAC,SAAS,CAAC,cAAc,IAAI,GAAG,CAAC,SAAS,CAAC,cAAc,IAAI,GAAG,CAAC,CAAC;AAChI,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
interface BackoffOptions {
|
|
2
|
+
/**
|
|
3
|
+
* The initial delay you want to apply. Default to 100ms
|
|
4
|
+
*/
|
|
5
|
+
delay?: number;
|
|
6
|
+
/**
|
|
7
|
+
* The number of times you want to attempt the function. Default 10
|
|
8
|
+
*/
|
|
9
|
+
numberOfAttempts?: number;
|
|
10
|
+
/**
|
|
11
|
+
* An optional max delay
|
|
12
|
+
*/
|
|
13
|
+
maxDelay?: number;
|
|
14
|
+
/**
|
|
15
|
+
* An initial multiplier to be taken to the power of the attempt number when deciding how long to wait. Default value of 2
|
|
16
|
+
*/
|
|
17
|
+
timeMultiple?: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Given a task, attempts to execute it a designated number of times, returning the eventual response
|
|
21
|
+
* @author Eric Webb <ewebb@factorearth.com>
|
|
22
|
+
* @param task The task we want to retry potentially
|
|
23
|
+
* @param evaluator A function to evaluate if the task executed successfully, or if it needs to be retried. Needs to return boolean
|
|
24
|
+
* @param options The configurable options for the module
|
|
25
|
+
* @returns The result of the function
|
|
26
|
+
*/
|
|
27
|
+
export declare function backoff<TaskResult, TaskArguments extends any[]>(task: (...args: TaskArguments) => Promise<TaskResult>, evaluator: (taskResult: TaskResult) => boolean, options?: BackoffOptions, ...taskArguments: TaskArguments): Promise<TaskResult | void>;
|
|
28
|
+
export {};
|
package/dist/backOff.js
CHANGED
|
@@ -1,48 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.backoff = void 0;
|
|
40
|
-
var delay_1 = require("./delay");
|
|
1
|
+
import { delay } from "./delay";
|
|
41
2
|
// Default values
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
3
|
+
const DELAY = 100;
|
|
4
|
+
const NUMBER_OF_ATTEMPTS = 10;
|
|
5
|
+
const MAX_DELAY = Infinity;
|
|
6
|
+
const TIME_MULTIPLE = 2;
|
|
46
7
|
/**
|
|
47
8
|
* Given a task, attempts to execute it a designated number of times, returning the eventual response
|
|
48
9
|
* @author Eric Webb <ewebb@factorearth.com>
|
|
@@ -51,48 +12,26 @@ var TIME_MULTIPLE = 2;
|
|
|
51
12
|
* @param options The configurable options for the module
|
|
52
13
|
* @returns The result of the function
|
|
53
14
|
*/
|
|
54
|
-
function backoff(task, evaluator, options) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
15
|
+
export async function backoff(task, evaluator, options, ...taskArguments) {
|
|
16
|
+
let attemptNumber = 0;
|
|
17
|
+
const maxAttempts = options?.numberOfAttempts || NUMBER_OF_ATTEMPTS;
|
|
18
|
+
const initialDelay = options?.delay || DELAY;
|
|
19
|
+
const maxDelay = options?.maxDelay || MAX_DELAY;
|
|
20
|
+
const timeMultiple = options?.timeMultiple || TIME_MULTIPLE;
|
|
21
|
+
while (attemptNumber < maxAttempts) {
|
|
22
|
+
const calculatedDelay = initialDelay * Math.pow(timeMultiple, attemptNumber);
|
|
23
|
+
const delayTime = Math.min(calculatedDelay, maxDelay);
|
|
24
|
+
await delay(delayTime);
|
|
25
|
+
try {
|
|
26
|
+
const taskResult = await task(...taskArguments);
|
|
27
|
+
const evaluatorResult = evaluator(taskResult);
|
|
28
|
+
if (evaluatorResult || !(attemptNumber + 1 < maxAttempts))
|
|
29
|
+
return taskResult;
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
// recordSentry({ error: err, msg: "Error executing backoff task" });
|
|
33
|
+
}
|
|
34
|
+
attemptNumber++;
|
|
58
35
|
}
|
|
59
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
60
|
-
var attemptNumber, maxAttempts, initialDelay, maxDelay, timeMultiple, calculatedDelay, delayTime, taskResult, evaluatorResult, err_1;
|
|
61
|
-
return __generator(this, function (_a) {
|
|
62
|
-
switch (_a.label) {
|
|
63
|
-
case 0:
|
|
64
|
-
attemptNumber = 0;
|
|
65
|
-
maxAttempts = (options === null || options === void 0 ? void 0 : options.numberOfAttempts) || NUMBER_OF_ATTEMPTS;
|
|
66
|
-
initialDelay = (options === null || options === void 0 ? void 0 : options.delay) || DELAY;
|
|
67
|
-
maxDelay = (options === null || options === void 0 ? void 0 : options.maxDelay) || MAX_DELAY;
|
|
68
|
-
timeMultiple = (options === null || options === void 0 ? void 0 : options.timeMultiple) || TIME_MULTIPLE;
|
|
69
|
-
_a.label = 1;
|
|
70
|
-
case 1:
|
|
71
|
-
if (!(attemptNumber < maxAttempts)) return [3 /*break*/, 7];
|
|
72
|
-
calculatedDelay = initialDelay * Math.pow(timeMultiple, attemptNumber);
|
|
73
|
-
delayTime = Math.min(calculatedDelay, maxDelay);
|
|
74
|
-
return [4 /*yield*/, (0, delay_1.delay)(delayTime)];
|
|
75
|
-
case 2:
|
|
76
|
-
_a.sent();
|
|
77
|
-
_a.label = 3;
|
|
78
|
-
case 3:
|
|
79
|
-
_a.trys.push([3, 5, , 6]);
|
|
80
|
-
return [4 /*yield*/, task.apply(void 0, taskArguments)];
|
|
81
|
-
case 4:
|
|
82
|
-
taskResult = _a.sent();
|
|
83
|
-
evaluatorResult = evaluator(taskResult);
|
|
84
|
-
if (evaluatorResult || !(attemptNumber + 1 < maxAttempts))
|
|
85
|
-
return [2 /*return*/, taskResult];
|
|
86
|
-
return [3 /*break*/, 6];
|
|
87
|
-
case 5:
|
|
88
|
-
err_1 = _a.sent();
|
|
89
|
-
return [3 /*break*/, 6];
|
|
90
|
-
case 6:
|
|
91
|
-
attemptNumber++;
|
|
92
|
-
return [3 /*break*/, 1];
|
|
93
|
-
case 7: return [2 /*return*/];
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
36
|
}
|
|
98
|
-
|
|
37
|
+
//# sourceMappingURL=backOff.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backOff.js","sourceRoot":"","sources":["../lib/backOff.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAqBhC,iBAAiB;AACjB,MAAM,KAAK,GAAG,GAAG,CAAC;AAClB,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAC9B,MAAM,SAAS,GAAG,QAAQ,CAAC;AAC3B,MAAM,aAAa,GAAG,CAAC,CAAC;AAExB;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAA0C,IAAqD,EAAE,SAA8C,EAAE,OAAwB,EAAE,GAAG,aAA4B;IACtO,IAAI,aAAa,GAAG,CAAC,CAAC;IACtB,MAAM,WAAW,GAAG,OAAO,EAAE,gBAAgB,IAAI,kBAAkB,CAAC;IACpE,MAAM,YAAY,GAAG,OAAO,EAAE,KAAK,IAAI,KAAK,CAAC;IAC7C,MAAM,QAAQ,GAAG,OAAO,EAAE,QAAQ,IAAI,SAAS,CAAC;IAChD,MAAM,YAAY,GAAG,OAAO,EAAE,YAAY,IAAI,aAAa,CAAC;IAC5D,OAAO,aAAa,GAAG,WAAW,EAAE,CAAC;QACpC,MAAM,eAAe,GAAG,YAAY,GAAG,IAAI,CAAC,GAAG,CAAC,YAAY,EAAE,aAAa,CAAC,CAAC;QAC7E,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAC;QACtD,MAAM,KAAK,CAAC,SAAS,CAAC,CAAC;QACvB,IAAI,CAAC;YACJ,MAAM,UAAU,GAAe,MAAM,IAAI,CAAC,GAAG,aAAa,CAAC,CAAC;YAC5D,MAAM,eAAe,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC;YAC9C,IAAI,eAAe,IAAI,CAAC,CAAC,aAAa,GAAG,CAAC,GAAG,WAAW,CAAC;gBAAE,OAAO,UAAU,CAAC;QAC9E,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACd,qEAAqE;QACtE,CAAC;QACD,aAAa,EAAE,CAAC;IACjB,CAAC;AACF,CAAC"}
|
package/dist/delay.d.ts
ADDED
package/dist/delay.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.delay = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* Creates a promise that resolvers after a provided number of ms
|
|
6
3
|
* @author Eric Webb <ewebb@factorearth.com>
|
|
7
4
|
* @param millis The number of ms you want to sleep
|
|
8
5
|
* @returns A void promise
|
|
9
6
|
*/
|
|
10
|
-
function delay(millis) {
|
|
11
|
-
return new Promise(
|
|
7
|
+
export function delay(millis) {
|
|
8
|
+
return new Promise((resolve, _reject) => setTimeout(resolve, millis));
|
|
12
9
|
}
|
|
13
|
-
|
|
10
|
+
//# sourceMappingURL=delay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delay.js","sourceRoot":"","sources":["../lib/delay.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,KAAK,CAAC,MAAc;IACnC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;AACvE,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Takes a given error, determines if we can bother retrying the operation, and re-attempts the operation
|
|
3
|
+
* @author Eric Webb <ewebb@factorearth.com>
|
|
4
|
+
* @param err The error thrown by the dynamodb sdk
|
|
5
|
+
* @param task The task that we need to try and perform, if it can be retried
|
|
6
|
+
* @param evaluator The function that evaluates the success of the task
|
|
7
|
+
* @param taskArguments The arguments we need to pass into the task
|
|
8
|
+
* @returns The result of the task, or the error that prevented it from executing
|
|
9
|
+
*/
|
|
10
|
+
export declare function handler<TaskResult, TaskArguments extends any[]>(err: unknown, task: (...args: TaskArguments[]) => Promise<TaskResult>, evaluator: (result: TaskResult) => boolean, ...taskArguments: TaskArguments): Promise<unknown>;
|
package/dist/handler.js
CHANGED
|
@@ -1,53 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
39
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
40
|
-
if (ar || !(i in from)) {
|
|
41
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
42
|
-
ar[i] = from[i];
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
46
|
-
};
|
|
47
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
-
exports.handler = void 0;
|
|
49
|
-
var determineRetryableDynamo_1 = require("./aws-services/dynamodb/determineRetryableDynamo");
|
|
50
|
-
var backOff_1 = require("./backOff");
|
|
1
|
+
import { determineRetryableDynamo } from "./aws-services/dynamodb/determineRetryableDynamo";
|
|
2
|
+
import { backoff } from "./backOff";
|
|
51
3
|
/**
|
|
52
4
|
* Takes a given error, determines if we can bother retrying the operation, and re-attempts the operation
|
|
53
5
|
* @author Eric Webb <ewebb@factorearth.com>
|
|
@@ -57,25 +9,12 @@ var backOff_1 = require("./backOff");
|
|
|
57
9
|
* @param taskArguments The arguments we need to pass into the task
|
|
58
10
|
* @returns The result of the task, or the error that prevented it from executing
|
|
59
11
|
*/
|
|
60
|
-
function handler(err, task, evaluator) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
12
|
+
export async function handler(err, task, evaluator, ...taskArguments) {
|
|
13
|
+
const canBeRetried = determineRetryableDynamo(err);
|
|
14
|
+
if (canBeRetried) {
|
|
15
|
+
const result = await backoff(task, evaluator, undefined, ...taskArguments);
|
|
16
|
+
return result;
|
|
64
17
|
}
|
|
65
|
-
return
|
|
66
|
-
var canBeRetried, result;
|
|
67
|
-
return __generator(this, function (_a) {
|
|
68
|
-
switch (_a.label) {
|
|
69
|
-
case 0:
|
|
70
|
-
canBeRetried = (0, determineRetryableDynamo_1.determineRetryableDynamo)(err);
|
|
71
|
-
if (!canBeRetried) return [3 /*break*/, 2];
|
|
72
|
-
return [4 /*yield*/, backOff_1.backoff.apply(void 0, __spreadArray([task, evaluator, undefined], taskArguments, false))];
|
|
73
|
-
case 1:
|
|
74
|
-
result = _a.sent();
|
|
75
|
-
return [2 /*return*/, result];
|
|
76
|
-
case 2: return [2 /*return*/, err];
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
});
|
|
18
|
+
return err;
|
|
80
19
|
}
|
|
81
|
-
|
|
20
|
+
//# sourceMappingURL=handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../lib/handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,kDAAkD,CAAC;AAC5F,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAA0C,GAAY,EAAE,IAAuD,EAAE,SAA0C,EAAE,GAAG,aAA4B;IACxN,MAAM,YAAY,GAAG,wBAAwB,CAAC,GAAG,CAAC,CAAC;IACnD,IAAI,YAAY,EAAE,CAAC;QAClB,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,aAAa,CAAC,CAAC;QAC3E,OAAO,MAAM,CAAC;IACf,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
CHANGED
|
@@ -1,19 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./aws-services/dynamodb/determineRetryableDynamo"), exports);
|
|
18
|
-
__exportStar(require("./backOff"), exports);
|
|
19
|
-
__exportStar(require("./handler"), exports);
|
|
1
|
+
export * from "./aws-services/dynamodb/determineRetryableDynamo";
|
|
2
|
+
export * from "./backOff";
|
|
3
|
+
export * from "./handler";
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,kDAAkD,CAAC;AACjE,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@factorearth/recordmiddleware-errorhandler",
|
|
3
|
-
"version": "0.0.1-y.
|
|
3
|
+
"version": "0.0.1-y.34",
|
|
4
4
|
"description": "A module for handling CRUD errors in lambda",
|
|
5
5
|
"author": "madtrx <marlin.makori@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/FactorEarth/RecordMiddleware#readme",
|
|
@@ -11,11 +11,7 @@
|
|
|
11
11
|
"dist"
|
|
12
12
|
],
|
|
13
13
|
"scripts": {
|
|
14
|
-
"
|
|
15
|
-
"clean": "rm -rf ./dist && rm -rf tsconfig.build.tsbuildinfo",
|
|
16
|
-
"compile": "tsc -b tsconfig.build.json",
|
|
17
|
-
"test": "node ./__tests__/errorHandler.test.js",
|
|
18
|
-
"prepublishOnly": "npm run build"
|
|
14
|
+
"test": "node ./__tests__/errorHandler.test.js"
|
|
19
15
|
},
|
|
20
16
|
"repository": {
|
|
21
17
|
"type": "git",
|
|
@@ -28,5 +24,5 @@
|
|
|
28
24
|
"access": "public",
|
|
29
25
|
"registry": "https://registry.npmjs.org/"
|
|
30
26
|
},
|
|
31
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "d8add266a795751bac8aa783381e4f4cf40af68b"
|
|
32
28
|
}
|