@terreno/api 0.27.0 → 0.29.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/dist/actions.test.js +2 -1
- package/dist/api.coverage.test.js +4 -2
- package/dist/api.errorPaths.test.js +5 -3
- package/dist/api.errors.test.js +6 -7
- package/dist/api.hooks.test.js +65 -8
- package/dist/api.js +93 -47
- package/dist/api.test.js +10 -4
- package/dist/auth.test.js +1 -1
- package/dist/config.js +7 -4
- package/dist/config.test.js +28 -3
- package/dist/docLoader.js +15 -51
- package/dist/docLoader.test.js +2 -1
- package/dist/errors.d.ts +72 -5
- package/dist/errors.js +265 -67
- package/dist/errors.test.js +163 -13
- package/dist/httpClient.d.ts +2 -3
- package/dist/httpClient.js +4 -4
- package/dist/httpClient.test.js +3 -2
- package/dist/notifiers/googleChatNotifier.test.js +2 -1
- package/dist/notifiers/slackNotifier.test.js +1 -1
- package/dist/notifiers/zoomNotifier.test.js +2 -1
- package/dist/permissions.js +0 -2
- package/dist/permissions.middleware.test.js +7 -42
- package/dist/plugins.test.js +4 -2
- package/dist/transformers.js +4 -2
- package/package.json +2 -2
- package/src/actions.test.ts +2 -1
- package/src/api.coverage.test.ts +4 -2
- package/src/api.errorPaths.test.ts +5 -3
- package/src/api.errors.test.ts +6 -7
- package/src/api.hooks.test.ts +24 -1
- package/src/api.test.ts +10 -4
- package/src/api.ts +93 -48
- package/src/auth.test.ts +1 -1
- package/src/config.test.ts +25 -3
- package/src/config.ts +7 -4
- package/src/docLoader.test.ts +2 -1
- package/src/docLoader.ts +16 -18
- package/src/errors.test.ts +178 -13
- package/src/errors.ts +278 -79
- package/src/httpClient.test.ts +3 -2
- package/src/httpClient.ts +4 -4
- package/src/notifiers/googleChatNotifier.test.ts +2 -2
- package/src/notifiers/slackNotifier.test.ts +2 -2
- package/src/notifiers/zoomNotifier.test.ts +2 -2
- package/src/permissions.middleware.test.ts +7 -11
- package/src/permissions.ts +0 -2
- package/src/plugins.test.ts +4 -2
- package/src/transformers.ts +4 -2
- package/tsconfig.json +1 -1
package/dist/actions.test.js
CHANGED
|
@@ -392,7 +392,8 @@ var allPermissions = {
|
|
|
392
392
|
return [4 /*yield*/, server.get("/food/".concat(missingId, "/peek")).expect(404)];
|
|
393
393
|
case 1:
|
|
394
394
|
res = _a.sent();
|
|
395
|
-
(0, bun_test_1.expect)(res.body.title).
|
|
395
|
+
(0, bun_test_1.expect)(res.body.title).toBe("Document not found");
|
|
396
|
+
(0, bun_test_1.expect)(res.body.detail).toContain(missingId);
|
|
396
397
|
(0, bun_test_1.expect)(res.body.meta).toBeUndefined();
|
|
397
398
|
return [2 /*return*/];
|
|
398
399
|
}
|
|
@@ -130,7 +130,8 @@ var ExplosiveModel = mongoose_1.default.model("ExplosiveCoverage", explosiveSche
|
|
|
130
130
|
return [4 /*yield*/, server.post("/food/".concat(apple._id, "/tags")).send({ tags: "organic" }).expect(403)];
|
|
131
131
|
case 1:
|
|
132
132
|
res = _a.sent();
|
|
133
|
-
(0, bun_test_1.expect)(res.body.title).
|
|
133
|
+
(0, bun_test_1.expect)(res.body.title).toBe("Transform error");
|
|
134
|
+
(0, bun_test_1.expect)(res.body.detail).toContain("array transform boom");
|
|
134
135
|
return [2 /*return*/];
|
|
135
136
|
}
|
|
136
137
|
});
|
|
@@ -183,7 +184,8 @@ var ExplosiveModel = mongoose_1.default.model("ExplosiveCoverage", explosiveSche
|
|
|
183
184
|
return [4 /*yield*/, server.delete("/explosive/".concat(doc._id)).expect(400)];
|
|
184
185
|
case 2:
|
|
185
186
|
res = _a.sent();
|
|
186
|
-
(0, bun_test_1.expect)(res.body.title).
|
|
187
|
+
(0, bun_test_1.expect)(res.body.title).toBe("Delete error");
|
|
188
|
+
(0, bun_test_1.expect)(res.body.detail).toContain("deleteOne exploded");
|
|
187
189
|
return [2 /*return*/];
|
|
188
190
|
}
|
|
189
191
|
});
|
|
@@ -148,7 +148,7 @@ var anyPermissions = {
|
|
|
148
148
|
case 1:
|
|
149
149
|
res = _a.sent();
|
|
150
150
|
chai_1.assert.include(res.body.title, "Populate error");
|
|
151
|
-
chai_1.assert.include(res.body.
|
|
151
|
+
chai_1.assert.include(res.body.detail, "populate exploded");
|
|
152
152
|
return [2 /*return*/];
|
|
153
153
|
}
|
|
154
154
|
});
|
|
@@ -219,7 +219,8 @@ var anyPermissions = {
|
|
|
219
219
|
return [4 /*yield*/, server.delete("/brittle/".concat(created._id)).expect(400)];
|
|
220
220
|
case 2:
|
|
221
221
|
res = _a.sent();
|
|
222
|
-
chai_1.assert.
|
|
222
|
+
chai_1.assert.equal(res.body.title, "Delete error");
|
|
223
|
+
chai_1.assert.include(res.body.detail, "deleteOne exploded");
|
|
223
224
|
return [2 /*return*/];
|
|
224
225
|
}
|
|
225
226
|
});
|
|
@@ -246,7 +247,8 @@ var anyPermissions = {
|
|
|
246
247
|
return [4 /*yield*/, server.post("/food/".concat(food._id, "/tags")).send({ tags: "vegetable" }).expect(403)];
|
|
247
248
|
case 2:
|
|
248
249
|
res = _a.sent();
|
|
249
|
-
chai_1.assert.
|
|
250
|
+
chai_1.assert.equal(res.body.title, "Transform error");
|
|
251
|
+
chai_1.assert.include(res.body.detail, "transform exploded");
|
|
250
252
|
return [2 /*return*/];
|
|
251
253
|
}
|
|
252
254
|
});
|
package/dist/api.errors.test.js
CHANGED
|
@@ -58,23 +58,22 @@ var errors_1 = require("./errors");
|
|
|
58
58
|
var error = new errors_1.APIError({ status: 600, title: "Test error" });
|
|
59
59
|
(0, bun_test_1.expect)(error.status).toBe(500);
|
|
60
60
|
});
|
|
61
|
-
(0, bun_test_1.it)("
|
|
61
|
+
(0, bun_test_1.it)("exposes a wrapped error as the cause, keeping the message stable", function () {
|
|
62
62
|
var originalError = new Error("Original error");
|
|
63
63
|
var apiError = new errors_1.APIError({
|
|
64
64
|
error: originalError,
|
|
65
65
|
title: "Wrapped error",
|
|
66
66
|
});
|
|
67
|
-
(0, bun_test_1.expect)(apiError.message).
|
|
68
|
-
(0, bun_test_1.expect)(
|
|
69
|
-
(0, bun_test_1.expect)(apiError.message).toContain(originalError.stack);
|
|
67
|
+
(0, bun_test_1.expect)(apiError.message).toBe("Wrapped error");
|
|
68
|
+
(0, bun_test_1.expect)(apiError.cause).toBe(originalError);
|
|
70
69
|
});
|
|
71
|
-
(0, bun_test_1.it)("
|
|
70
|
+
(0, bun_test_1.it)("keeps detail out of the message", function () {
|
|
72
71
|
var error = new errors_1.APIError({
|
|
73
72
|
detail: "More details here",
|
|
74
73
|
title: "Test error",
|
|
75
74
|
});
|
|
76
|
-
(0, bun_test_1.expect)(error.message).
|
|
77
|
-
(0, bun_test_1.expect)(error.
|
|
75
|
+
(0, bun_test_1.expect)(error.message).toBe("Test error");
|
|
76
|
+
(0, bun_test_1.expect)(error.detail).toBe("More details here");
|
|
78
77
|
});
|
|
79
78
|
(0, bun_test_1.it)("sets fields in meta when provided", function () {
|
|
80
79
|
var _a;
|
package/dist/api.hooks.test.js
CHANGED
|
@@ -1,4 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
36
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
37
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -58,28 +91,32 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
58
91
|
// noExplicitAny: test mock typing
|
|
59
92
|
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
60
93
|
var bun_test_1 = require("bun:test");
|
|
94
|
+
var Sentry = __importStar(require("@sentry/bun"));
|
|
61
95
|
var supertest_1 = __importDefault(require("supertest"));
|
|
62
96
|
var api_1 = require("./api");
|
|
63
97
|
var auth_1 = require("./auth");
|
|
64
98
|
var errors_1 = require("./errors");
|
|
65
99
|
var permissions_1 = require("./permissions");
|
|
66
100
|
var tests_1 = require("./tests");
|
|
101
|
+
var captureExceptionMock = Sentry.captureException;
|
|
67
102
|
(0, bun_test_1.describe)("pre and post hooks", function () {
|
|
68
103
|
var server;
|
|
69
104
|
var app;
|
|
70
105
|
var agent;
|
|
71
106
|
(0, bun_test_1.beforeEach)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
72
|
-
|
|
73
|
-
|
|
107
|
+
var _a;
|
|
108
|
+
return __generator(this, function (_b) {
|
|
109
|
+
switch (_b.label) {
|
|
74
110
|
case 0: return [4 /*yield*/, (0, tests_1.setupDb)()];
|
|
75
111
|
case 1:
|
|
76
|
-
|
|
112
|
+
_b.sent();
|
|
77
113
|
app = (0, tests_1.getBaseServer)();
|
|
78
114
|
(0, auth_1.setupAuth)(app, tests_1.UserModel);
|
|
79
115
|
(0, auth_1.addAuthRoutes)(app, tests_1.UserModel);
|
|
80
116
|
return [4 /*yield*/, (0, tests_1.authAsUser)(app, "notAdmin")];
|
|
81
117
|
case 2:
|
|
82
|
-
agent =
|
|
118
|
+
agent = _b.sent();
|
|
119
|
+
(_a = captureExceptionMock.mockClear) === null || _a === void 0 ? void 0 : _a.call(captureExceptionMock);
|
|
83
120
|
return [2 /*return*/];
|
|
84
121
|
}
|
|
85
122
|
});
|
|
@@ -334,7 +371,10 @@ var tests_1 = require("./tests");
|
|
|
334
371
|
case 1:
|
|
335
372
|
res = _a.sent();
|
|
336
373
|
(0, bun_test_1.expect)(res.body.title).toBe("Custom preCreate error");
|
|
374
|
+
// Serialized when true so the frontend can suppress duplicate Sentry reporting; also
|
|
375
|
+
// suppresses Sentry capture in apiErrorMiddleware.
|
|
337
376
|
(0, bun_test_1.expect)(res.body.disableExternalErrorTracking).toBe(true);
|
|
377
|
+
(0, bun_test_1.expect)(captureExceptionMock).not.toHaveBeenCalled();
|
|
338
378
|
return [2 /*return*/];
|
|
339
379
|
}
|
|
340
380
|
});
|
|
@@ -370,7 +410,10 @@ var tests_1 = require("./tests");
|
|
|
370
410
|
case 1:
|
|
371
411
|
res = _a.sent();
|
|
372
412
|
(0, bun_test_1.expect)(res.body.title).toContain("preCreate hook error");
|
|
413
|
+
// Serialized when true so the frontend can suppress duplicate Sentry reporting; also
|
|
414
|
+
// suppresses Sentry capture in apiErrorMiddleware.
|
|
373
415
|
(0, bun_test_1.expect)(res.body.disableExternalErrorTracking).toBe(true);
|
|
416
|
+
(0, bun_test_1.expect)(captureExceptionMock).not.toHaveBeenCalled();
|
|
374
417
|
return [2 /*return*/];
|
|
375
418
|
}
|
|
376
419
|
});
|
|
@@ -423,7 +466,10 @@ var tests_1 = require("./tests");
|
|
|
423
466
|
case 3:
|
|
424
467
|
res = _a.sent();
|
|
425
468
|
(0, bun_test_1.expect)(res.body.title).toBe("Custom preUpdate error");
|
|
469
|
+
// Serialized when true so the frontend can suppress duplicate Sentry reporting; also
|
|
470
|
+
// suppresses Sentry capture in apiErrorMiddleware.
|
|
426
471
|
(0, bun_test_1.expect)(res.body.disableExternalErrorTracking).toBe(true);
|
|
472
|
+
(0, bun_test_1.expect)(captureExceptionMock).not.toHaveBeenCalled();
|
|
427
473
|
return [2 /*return*/];
|
|
428
474
|
}
|
|
429
475
|
});
|
|
@@ -474,7 +520,10 @@ var tests_1 = require("./tests");
|
|
|
474
520
|
case 3:
|
|
475
521
|
res = _a.sent();
|
|
476
522
|
(0, bun_test_1.expect)(res.body.title).toContain("preUpdate hook error");
|
|
523
|
+
// Serialized when true so the frontend can suppress duplicate Sentry reporting; also
|
|
524
|
+
// suppresses Sentry capture in apiErrorMiddleware.
|
|
477
525
|
(0, bun_test_1.expect)(res.body.disableExternalErrorTracking).toBe(true);
|
|
526
|
+
(0, bun_test_1.expect)(captureExceptionMock).not.toHaveBeenCalled();
|
|
478
527
|
return [2 /*return*/];
|
|
479
528
|
}
|
|
480
529
|
});
|
|
@@ -520,7 +569,10 @@ var tests_1 = require("./tests");
|
|
|
520
569
|
case 3:
|
|
521
570
|
res = _a.sent();
|
|
522
571
|
(0, bun_test_1.expect)(res.body.title).toContain("preDelete hook error");
|
|
572
|
+
// Serialized when true so the frontend can suppress duplicate Sentry reporting; also
|
|
573
|
+
// suppresses Sentry capture in apiErrorMiddleware.
|
|
523
574
|
(0, bun_test_1.expect)(res.body.disableExternalErrorTracking).toBe(true);
|
|
575
|
+
(0, bun_test_1.expect)(captureExceptionMock).not.toHaveBeenCalled();
|
|
524
576
|
return [2 /*return*/];
|
|
525
577
|
}
|
|
526
578
|
});
|
|
@@ -534,11 +586,12 @@ var tests_1 = require("./tests");
|
|
|
534
586
|
var spinach;
|
|
535
587
|
(0, bun_test_1.beforeEach)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
536
588
|
var _a;
|
|
537
|
-
|
|
538
|
-
|
|
589
|
+
var _b;
|
|
590
|
+
return __generator(this, function (_c) {
|
|
591
|
+
switch (_c.label) {
|
|
539
592
|
case 0: return [4 /*yield*/, (0, tests_1.setupDb)()];
|
|
540
593
|
case 1:
|
|
541
|
-
_a = __read.apply(void 0, [
|
|
594
|
+
_a = __read.apply(void 0, [_c.sent(), 1]), admin = _a[0];
|
|
542
595
|
return [4 /*yield*/, tests_1.FoodModel.create({
|
|
543
596
|
calories: 1,
|
|
544
597
|
created: new Date("2021-12-03T00:00:20.000Z"),
|
|
@@ -550,10 +603,11 @@ var tests_1 = require("./tests");
|
|
|
550
603
|
},
|
|
551
604
|
})];
|
|
552
605
|
case 2:
|
|
553
|
-
spinach =
|
|
606
|
+
spinach = _c.sent();
|
|
554
607
|
app = (0, tests_1.getBaseServer)();
|
|
555
608
|
(0, auth_1.setupAuth)(app, tests_1.UserModel);
|
|
556
609
|
(0, auth_1.addAuthRoutes)(app, tests_1.UserModel);
|
|
610
|
+
(_b = captureExceptionMock.mockClear) === null || _b === void 0 ? void 0 : _b.call(captureExceptionMock);
|
|
557
611
|
return [2 /*return*/];
|
|
558
612
|
}
|
|
559
613
|
});
|
|
@@ -885,7 +939,10 @@ var tests_1 = require("./tests");
|
|
|
885
939
|
case 2:
|
|
886
940
|
res = _a.sent();
|
|
887
941
|
(0, bun_test_1.expect)(res.body.title).toBe("Custom preDelete APIError");
|
|
942
|
+
// Serialized when true so the frontend can suppress duplicate Sentry reporting; also
|
|
943
|
+
// suppresses Sentry capture in apiErrorMiddleware.
|
|
888
944
|
(0, bun_test_1.expect)(res.body.disableExternalErrorTracking).toBe(true);
|
|
945
|
+
(0, bun_test_1.expect)(captureExceptionMock).not.toHaveBeenCalled();
|
|
889
946
|
return [2 /*return*/];
|
|
890
947
|
}
|
|
891
948
|
});
|
package/dist/api.js
CHANGED
|
@@ -207,7 +207,7 @@ var mergeDateRangeQueryParams = function (model, query) {
|
|
|
207
207
|
}
|
|
208
208
|
var baseField = match[1];
|
|
209
209
|
var path = schema.path(baseField);
|
|
210
|
-
if (
|
|
210
|
+
if ((path === null || path === void 0 ? void 0 : path.instance) !== "Date") {
|
|
211
211
|
continue;
|
|
212
212
|
}
|
|
213
213
|
dateRangeBases.add(baseField);
|
|
@@ -451,10 +451,12 @@ function _buildModelRouter(model, options) {
|
|
|
451
451
|
throw error;
|
|
452
452
|
}
|
|
453
453
|
throw new errors_1.APIError({
|
|
454
|
+
cause: error,
|
|
455
|
+
code: "transform-error",
|
|
456
|
+
detail: (0, errors_1.errorMessage)(error),
|
|
454
457
|
disableExternalErrorTracking: (0, errors_1.getDisableExternalErrorTracking)(error),
|
|
455
|
-
error: error,
|
|
456
458
|
status: 400,
|
|
457
|
-
title:
|
|
459
|
+
title: "Transform error",
|
|
458
460
|
});
|
|
459
461
|
}
|
|
460
462
|
if (!options.preCreate) return [3 /*break*/, 5];
|
|
@@ -471,10 +473,12 @@ function _buildModelRouter(model, options) {
|
|
|
471
473
|
throw error_1;
|
|
472
474
|
}
|
|
473
475
|
throw new errors_1.APIError({
|
|
476
|
+
cause: error_1,
|
|
477
|
+
code: "pre-create-hook-error",
|
|
478
|
+
detail: (0, errors_1.errorMessage)(error_1),
|
|
474
479
|
disableExternalErrorTracking: (0, errors_1.getDisableExternalErrorTracking)(error_1),
|
|
475
|
-
error: error_1,
|
|
476
480
|
status: 400,
|
|
477
|
-
title: "preCreate hook error
|
|
481
|
+
title: "preCreate hook error",
|
|
478
482
|
});
|
|
479
483
|
case 4:
|
|
480
484
|
if (body === undefined) {
|
|
@@ -510,10 +514,12 @@ function _buildModelRouter(model, options) {
|
|
|
510
514
|
case 8:
|
|
511
515
|
error_2 = _a.sent();
|
|
512
516
|
throw new errors_1.APIError({
|
|
517
|
+
cause: error_2,
|
|
518
|
+
code: "create-error",
|
|
519
|
+
detail: (0, errors_1.errorMessage)(error_2),
|
|
513
520
|
disableExternalErrorTracking: (0, errors_1.getDisableExternalErrorTracking)(error_2),
|
|
514
|
-
error: error_2,
|
|
515
521
|
status: 400,
|
|
516
|
-
title:
|
|
522
|
+
title: "Create error",
|
|
517
523
|
});
|
|
518
524
|
case 9:
|
|
519
525
|
if (!options.populatePaths) return [3 /*break*/, 13];
|
|
@@ -529,10 +535,12 @@ function _buildModelRouter(model, options) {
|
|
|
529
535
|
case 12:
|
|
530
536
|
error_3 = _a.sent();
|
|
531
537
|
throw new errors_1.APIError({
|
|
538
|
+
cause: error_3,
|
|
539
|
+
code: "populate-error",
|
|
540
|
+
detail: (0, errors_1.errorMessage)(error_3),
|
|
532
541
|
disableExternalErrorTracking: (0, errors_1.getDisableExternalErrorTracking)(error_3),
|
|
533
|
-
error: error_3,
|
|
534
542
|
status: 400,
|
|
535
|
-
title: "Populate error
|
|
543
|
+
title: "Populate error",
|
|
536
544
|
});
|
|
537
545
|
case 13:
|
|
538
546
|
if (!options.postCreate) return [3 /*break*/, 17];
|
|
@@ -546,10 +554,12 @@ function _buildModelRouter(model, options) {
|
|
|
546
554
|
case 16:
|
|
547
555
|
error_4 = _a.sent();
|
|
548
556
|
throw new errors_1.APIError({
|
|
557
|
+
cause: error_4,
|
|
558
|
+
code: "post-create-hook-error",
|
|
559
|
+
detail: (0, errors_1.errorMessage)(error_4),
|
|
549
560
|
disableExternalErrorTracking: (0, errors_1.getDisableExternalErrorTracking)(error_4),
|
|
550
|
-
error: error_4,
|
|
551
561
|
status: 400,
|
|
552
|
-
title: "postCreate hook error
|
|
562
|
+
title: "postCreate hook error",
|
|
553
563
|
});
|
|
554
564
|
case 17:
|
|
555
565
|
_a.trys.push([17, 19, , 20]);
|
|
@@ -560,9 +570,11 @@ function _buildModelRouter(model, options) {
|
|
|
560
570
|
case 19:
|
|
561
571
|
error_5 = _a.sent();
|
|
562
572
|
throw new errors_1.APIError({
|
|
573
|
+
cause: error_5,
|
|
574
|
+
code: "response-handler-error",
|
|
575
|
+
detail: (0, errors_1.errorMessage)(error_5),
|
|
563
576
|
disableExternalErrorTracking: (0, errors_1.getDisableExternalErrorTracking)(error_5),
|
|
564
|
-
|
|
565
|
-
title: "responseHandler error: ".concat((0, errors_1.errorMessage)(error_5)),
|
|
577
|
+
title: "responseHandler error",
|
|
566
578
|
});
|
|
567
579
|
case 20: return [2 /*return*/];
|
|
568
580
|
}
|
|
@@ -641,10 +653,12 @@ function _buildModelRouter(model, options) {
|
|
|
641
653
|
case 3:
|
|
642
654
|
error_6 = _o.sent();
|
|
643
655
|
throw new errors_1.APIError({
|
|
656
|
+
cause: error_6,
|
|
657
|
+
code: "query-filter-error",
|
|
658
|
+
detail: String(error_6),
|
|
644
659
|
disableExternalErrorTracking: (0, errors_1.getDisableExternalErrorTracking)(error_6),
|
|
645
|
-
error: error_6,
|
|
646
660
|
status: 400,
|
|
647
|
-
title: "Query filter error
|
|
661
|
+
title: "Query filter error",
|
|
648
662
|
});
|
|
649
663
|
case 4:
|
|
650
664
|
// If the query filter returns null specifically, we know this is a query that shouldn't
|
|
@@ -695,9 +709,11 @@ function _buildModelRouter(model, options) {
|
|
|
695
709
|
case 9:
|
|
696
710
|
error_7 = _o.sent();
|
|
697
711
|
throw new errors_1.APIError({
|
|
712
|
+
cause: error_7,
|
|
713
|
+
code: "list-error",
|
|
714
|
+
detail: (0, errors_1.errorMessage)(error_7),
|
|
698
715
|
disableExternalErrorTracking: (0, errors_1.getDisableExternalErrorTracking)(error_7),
|
|
699
|
-
|
|
700
|
-
title: "List error: ".concat((0, errors_1.errorStack)(error_7)),
|
|
716
|
+
title: "List error",
|
|
701
717
|
});
|
|
702
718
|
case 10:
|
|
703
719
|
_o.trys.push([10, 12, , 13]);
|
|
@@ -708,9 +724,11 @@ function _buildModelRouter(model, options) {
|
|
|
708
724
|
case 12:
|
|
709
725
|
error_8 = _o.sent();
|
|
710
726
|
throw new errors_1.APIError({
|
|
727
|
+
cause: error_8,
|
|
728
|
+
code: "response-handler-error",
|
|
729
|
+
detail: (0, errors_1.errorMessage)(error_8),
|
|
711
730
|
disableExternalErrorTracking: (0, errors_1.getDisableExternalErrorTracking)(error_8),
|
|
712
|
-
|
|
713
|
-
title: "responseHandler error: ".concat((0, errors_1.errorMessage)(error_8)),
|
|
731
|
+
title: "responseHandler error",
|
|
714
732
|
});
|
|
715
733
|
case 13:
|
|
716
734
|
try {
|
|
@@ -742,9 +760,11 @@ function _buildModelRouter(model, options) {
|
|
|
742
760
|
}
|
|
743
761
|
catch (error) {
|
|
744
762
|
throw new errors_1.APIError({
|
|
763
|
+
cause: error,
|
|
764
|
+
code: "serialization-error",
|
|
765
|
+
detail: (0, errors_1.errorMessage)(error),
|
|
745
766
|
disableExternalErrorTracking: (0, errors_1.getDisableExternalErrorTracking)(error),
|
|
746
|
-
|
|
747
|
-
title: "Serialization error: ".concat((0, errors_1.errorMessage)(error)),
|
|
767
|
+
title: "Serialization error",
|
|
748
768
|
});
|
|
749
769
|
}
|
|
750
770
|
return [2 /*return*/];
|
|
@@ -771,9 +791,11 @@ function _buildModelRouter(model, options) {
|
|
|
771
791
|
case 3:
|
|
772
792
|
error_9 = _a.sent();
|
|
773
793
|
throw new errors_1.APIError({
|
|
794
|
+
cause: error_9,
|
|
795
|
+
code: "response-handler-error",
|
|
796
|
+
detail: (0, errors_1.errorMessage)(error_9),
|
|
774
797
|
disableExternalErrorTracking: (0, errors_1.getDisableExternalErrorTracking)(error_9),
|
|
775
|
-
|
|
776
|
-
title: "responseHandler error: ".concat((0, errors_1.errorMessage)(error_9)),
|
|
798
|
+
title: "responseHandler error",
|
|
777
799
|
});
|
|
778
800
|
case 4: return [2 /*return*/];
|
|
779
801
|
}
|
|
@@ -807,10 +829,12 @@ function _buildModelRouter(model, options) {
|
|
|
807
829
|
throw error;
|
|
808
830
|
}
|
|
809
831
|
throw new errors_1.APIError({
|
|
832
|
+
cause: error,
|
|
833
|
+
code: "transform-error",
|
|
834
|
+
detail: "PATCH failed on ".concat(req.params.id, " for user ").concat((_a = req.user) === null || _a === void 0 ? void 0 : _a.id, ": ").concat((0, errors_1.errorMessage)(error)),
|
|
810
835
|
disableExternalErrorTracking: (0, errors_1.getDisableExternalErrorTracking)(error),
|
|
811
|
-
error: error,
|
|
812
836
|
status: 403,
|
|
813
|
-
title: "PATCH failed
|
|
837
|
+
title: "PATCH failed",
|
|
814
838
|
});
|
|
815
839
|
}
|
|
816
840
|
bodyUpdatedAt = req.body._updatedAt;
|
|
@@ -832,10 +856,12 @@ function _buildModelRouter(model, options) {
|
|
|
832
856
|
throw error_10;
|
|
833
857
|
}
|
|
834
858
|
throw new errors_1.APIError({
|
|
859
|
+
cause: error_10,
|
|
860
|
+
code: "pre-update-hook-error",
|
|
861
|
+
detail: "preUpdate hook error on ".concat(req.params.id, ": ").concat((0, errors_1.errorMessage)(error_10)),
|
|
835
862
|
disableExternalErrorTracking: (0, errors_1.getDisableExternalErrorTracking)(error_10),
|
|
836
|
-
error: error_10,
|
|
837
863
|
status: 400,
|
|
838
|
-
title: "preUpdate hook error
|
|
864
|
+
title: "preUpdate hook error",
|
|
839
865
|
});
|
|
840
866
|
case 4:
|
|
841
867
|
if (body === undefined) {
|
|
@@ -919,10 +945,12 @@ function _buildModelRouter(model, options) {
|
|
|
919
945
|
case 10:
|
|
920
946
|
error_11 = _c.sent();
|
|
921
947
|
throw new errors_1.APIError({
|
|
948
|
+
cause: error_11,
|
|
949
|
+
code: "update-save-error",
|
|
950
|
+
detail: "preUpdate hook save error on ".concat(req.params.id, ": ").concat((0, errors_1.errorMessage)(error_11)),
|
|
922
951
|
disableExternalErrorTracking: (0, errors_1.getDisableExternalErrorTracking)(error_11),
|
|
923
|
-
error: error_11,
|
|
924
952
|
status: 400,
|
|
925
|
-
title: "preUpdate hook save error
|
|
953
|
+
title: "preUpdate hook save error",
|
|
926
954
|
});
|
|
927
955
|
case 11:
|
|
928
956
|
if (!options.populatePaths) return [3 /*break*/, 13];
|
|
@@ -944,10 +972,12 @@ function _buildModelRouter(model, options) {
|
|
|
944
972
|
case 16:
|
|
945
973
|
error_12 = _c.sent();
|
|
946
974
|
throw new errors_1.APIError({
|
|
975
|
+
cause: error_12,
|
|
976
|
+
code: "post-update-hook-error",
|
|
977
|
+
detail: "postUpdate hook error on ".concat(req.params.id, ": ").concat((0, errors_1.errorMessage)(error_12)),
|
|
947
978
|
disableExternalErrorTracking: (0, errors_1.getDisableExternalErrorTracking)(error_12),
|
|
948
|
-
error: error_12,
|
|
949
979
|
status: 400,
|
|
950
|
-
title: "postUpdate hook error
|
|
980
|
+
title: "postUpdate hook error",
|
|
951
981
|
});
|
|
952
982
|
case 17:
|
|
953
983
|
_c.trys.push([17, 19, , 20]);
|
|
@@ -958,9 +988,11 @@ function _buildModelRouter(model, options) {
|
|
|
958
988
|
case 19:
|
|
959
989
|
error_13 = _c.sent();
|
|
960
990
|
throw new errors_1.APIError({
|
|
991
|
+
cause: error_13,
|
|
992
|
+
code: "response-handler-error",
|
|
993
|
+
detail: (0, errors_1.errorMessage)(error_13),
|
|
961
994
|
disableExternalErrorTracking: (0, errors_1.getDisableExternalErrorTracking)(error_13),
|
|
962
|
-
|
|
963
|
-
title: "responseHandler error: ".concat((0, errors_1.errorMessage)(error_13)),
|
|
995
|
+
title: "responseHandler error",
|
|
964
996
|
});
|
|
965
997
|
case 20: return [2 /*return*/];
|
|
966
998
|
}
|
|
@@ -991,10 +1023,12 @@ function _buildModelRouter(model, options) {
|
|
|
991
1023
|
throw error_14;
|
|
992
1024
|
}
|
|
993
1025
|
throw new errors_1.APIError({
|
|
1026
|
+
cause: error_14,
|
|
1027
|
+
code: "pre-delete-hook-error",
|
|
1028
|
+
detail: "preDelete hook error on ".concat(req.params.id, ": ").concat((0, errors_1.errorMessage)(error_14)),
|
|
994
1029
|
disableExternalErrorTracking: (0, errors_1.getDisableExternalErrorTracking)(error_14),
|
|
995
|
-
error: error_14,
|
|
996
1030
|
status: 403,
|
|
997
|
-
title: "preDelete hook error
|
|
1031
|
+
title: "preDelete hook error",
|
|
998
1032
|
});
|
|
999
1033
|
case 4:
|
|
1000
1034
|
if (body === undefined) {
|
|
@@ -1029,10 +1063,12 @@ function _buildModelRouter(model, options) {
|
|
|
1029
1063
|
case 9:
|
|
1030
1064
|
error_15 = _a.sent();
|
|
1031
1065
|
throw new errors_1.APIError({
|
|
1066
|
+
cause: error_15,
|
|
1067
|
+
code: "delete-error",
|
|
1068
|
+
detail: (0, errors_1.errorMessage)(error_15),
|
|
1032
1069
|
disableExternalErrorTracking: (0, errors_1.getDisableExternalErrorTracking)(error_15),
|
|
1033
|
-
error: error_15,
|
|
1034
1070
|
status: 400,
|
|
1035
|
-
title:
|
|
1071
|
+
title: "Delete error",
|
|
1036
1072
|
});
|
|
1037
1073
|
case 10:
|
|
1038
1074
|
if (!options.postDelete) return [3 /*break*/, 14];
|
|
@@ -1046,10 +1082,12 @@ function _buildModelRouter(model, options) {
|
|
|
1046
1082
|
case 13:
|
|
1047
1083
|
error_16 = _a.sent();
|
|
1048
1084
|
throw new errors_1.APIError({
|
|
1085
|
+
cause: error_16,
|
|
1086
|
+
code: "post-delete-hook-error",
|
|
1087
|
+
detail: (0, errors_1.errorMessage)(error_16),
|
|
1049
1088
|
disableExternalErrorTracking: (0, errors_1.getDisableExternalErrorTracking)(error_16),
|
|
1050
|
-
error: error_16,
|
|
1051
1089
|
status: 400,
|
|
1052
|
-
title: "postDelete hook error
|
|
1090
|
+
title: "postDelete hook error",
|
|
1053
1091
|
});
|
|
1054
1092
|
case 14: return [2 /*return*/, res.status(204).json({})];
|
|
1055
1093
|
}
|
|
@@ -1144,10 +1182,12 @@ function _buildModelRouter(model, options) {
|
|
|
1144
1182
|
throw error;
|
|
1145
1183
|
}
|
|
1146
1184
|
throw new errors_1.APIError({
|
|
1185
|
+
cause: error,
|
|
1186
|
+
code: "transform-error",
|
|
1187
|
+
detail: (0, errors_1.errorMessage)(error),
|
|
1147
1188
|
disableExternalErrorTracking: (0, errors_1.getDisableExternalErrorTracking)(error),
|
|
1148
|
-
error: error,
|
|
1149
1189
|
status: 403,
|
|
1150
|
-
title:
|
|
1190
|
+
title: "Transform error",
|
|
1151
1191
|
});
|
|
1152
1192
|
}
|
|
1153
1193
|
if (!options.preUpdate) return [3 /*break*/, 8];
|
|
@@ -1161,10 +1201,12 @@ function _buildModelRouter(model, options) {
|
|
|
1161
1201
|
case 6:
|
|
1162
1202
|
error_17 = _d.sent();
|
|
1163
1203
|
throw new errors_1.APIError({
|
|
1204
|
+
cause: error_17,
|
|
1205
|
+
code: "pre-update-hook-error",
|
|
1206
|
+
detail: "preUpdate hook error on ".concat(req.params.id, ": ").concat((0, errors_1.errorMessage)(error_17)),
|
|
1164
1207
|
disableExternalErrorTracking: (0, errors_1.getDisableExternalErrorTracking)(error_17),
|
|
1165
|
-
error: error_17,
|
|
1166
1208
|
status: 400,
|
|
1167
|
-
title: "preUpdate hook error
|
|
1209
|
+
title: "preUpdate hook error",
|
|
1168
1210
|
});
|
|
1169
1211
|
case 7:
|
|
1170
1212
|
if (body === undefined) {
|
|
@@ -1192,10 +1234,12 @@ function _buildModelRouter(model, options) {
|
|
|
1192
1234
|
case 10:
|
|
1193
1235
|
error_18 = _d.sent();
|
|
1194
1236
|
throw new errors_1.APIError({
|
|
1237
|
+
cause: error_18,
|
|
1238
|
+
code: "update-save-error",
|
|
1239
|
+
detail: "PATCH Pre Update error on ".concat(req.params.id, ": ").concat((0, errors_1.errorMessage)(error_18)),
|
|
1195
1240
|
disableExternalErrorTracking: (0, errors_1.getDisableExternalErrorTracking)(error_18),
|
|
1196
|
-
error: error_18,
|
|
1197
1241
|
status: 400,
|
|
1198
|
-
title: "PATCH Pre Update error
|
|
1242
|
+
title: "PATCH Pre Update error",
|
|
1199
1243
|
});
|
|
1200
1244
|
case 11:
|
|
1201
1245
|
if (!options.postUpdate) return [3 /*break*/, 15];
|
|
@@ -1209,10 +1253,12 @@ function _buildModelRouter(model, options) {
|
|
|
1209
1253
|
case 14:
|
|
1210
1254
|
error_19 = _d.sent();
|
|
1211
1255
|
throw new errors_1.APIError({
|
|
1256
|
+
cause: error_19,
|
|
1257
|
+
code: "post-update-hook-error",
|
|
1258
|
+
detail: "PATCH Post Update error on ".concat(req.params.id, ": ").concat((0, errors_1.errorMessage)(error_19)),
|
|
1212
1259
|
disableExternalErrorTracking: (0, errors_1.getDisableExternalErrorTracking)(error_19),
|
|
1213
|
-
error: error_19,
|
|
1214
1260
|
status: 400,
|
|
1215
|
-
title: "PATCH Post Update error
|
|
1261
|
+
title: "PATCH Post Update error",
|
|
1216
1262
|
});
|
|
1217
1263
|
case 15: return [2 /*return*/, res.json({
|
|
1218
1264
|
data: (0, transformers_1.serialize)(req, options, doc),
|
package/dist/api.test.js
CHANGED
|
@@ -832,7 +832,8 @@ var transformers_1 = require("./transformers");
|
|
|
832
832
|
return [4 /*yield*/, server.post("/required").send({ about: "test" }).expect(400)];
|
|
833
833
|
case 1:
|
|
834
834
|
res = _a.sent();
|
|
835
|
-
(0, bun_test_1.expect)(res.body.title).
|
|
835
|
+
(0, bun_test_1.expect)(res.body.title).toBe("Create error");
|
|
836
|
+
(0, bun_test_1.expect)(res.body.detail).toContain("Required");
|
|
836
837
|
return [2 /*return*/];
|
|
837
838
|
}
|
|
838
839
|
});
|
|
@@ -867,6 +868,7 @@ var transformers_1 = require("./transformers");
|
|
|
867
868
|
case 2:
|
|
868
869
|
res = _a.sent();
|
|
869
870
|
(0, bun_test_1.expect)(res.body.title).toBe("Custom preDelete APIError");
|
|
871
|
+
// Serialized when true so the frontend can suppress duplicate Sentry reporting.
|
|
870
872
|
(0, bun_test_1.expect)(res.body.disableExternalErrorTracking).toBe(true);
|
|
871
873
|
return [2 /*return*/];
|
|
872
874
|
}
|
|
@@ -1760,7 +1762,8 @@ var transformers_1 = require("./transformers");
|
|
|
1760
1762
|
return [4 /*yield*/, server.post("/required").send({ about: "test" }).expect(400)];
|
|
1761
1763
|
case 2:
|
|
1762
1764
|
res = _a.sent();
|
|
1763
|
-
(0, bun_test_1.expect)(res.body.title).
|
|
1765
|
+
(0, bun_test_1.expect)(res.body.title).toBe("Create error");
|
|
1766
|
+
(0, bun_test_1.expect)(res.body.detail).toContain("Required");
|
|
1764
1767
|
return [2 /*return*/];
|
|
1765
1768
|
}
|
|
1766
1769
|
});
|
|
@@ -1795,6 +1798,7 @@ var transformers_1 = require("./transformers");
|
|
|
1795
1798
|
case 2:
|
|
1796
1799
|
res = _a.sent();
|
|
1797
1800
|
(0, bun_test_1.expect)(res.body.title).toBe("Custom preDelete APIError");
|
|
1801
|
+
// Serialized when true so the frontend can suppress duplicate Sentry reporting.
|
|
1798
1802
|
(0, bun_test_1.expect)(res.body.disableExternalErrorTracking).toBe(true);
|
|
1799
1803
|
return [2 /*return*/];
|
|
1800
1804
|
}
|
|
@@ -2741,7 +2745,8 @@ var transformers_1 = require("./transformers");
|
|
|
2741
2745
|
.expect(400)];
|
|
2742
2746
|
case 1:
|
|
2743
2747
|
res = _a.sent();
|
|
2744
|
-
(0, bun_test_1.expect)(res.body.title).
|
|
2748
|
+
(0, bun_test_1.expect)(res.body.title).toBe("Transform error");
|
|
2749
|
+
(0, bun_test_1.expect)(res.body.detail).toContain("generic transform error");
|
|
2745
2750
|
return [2 /*return*/];
|
|
2746
2751
|
}
|
|
2747
2752
|
});
|
|
@@ -2799,7 +2804,8 @@ var transformers_1 = require("./transformers");
|
|
|
2799
2804
|
case 0: return [4 /*yield*/, agent.patch("/food/".concat(spinach._id)).send({ name: "Updated" }).expect(403)];
|
|
2800
2805
|
case 1:
|
|
2801
2806
|
res = _a.sent();
|
|
2802
|
-
(0, bun_test_1.expect)(res.body.title).
|
|
2807
|
+
(0, bun_test_1.expect)(res.body.title).toBe("PATCH failed");
|
|
2808
|
+
(0, bun_test_1.expect)(res.body.detail).toContain("update transform error");
|
|
2803
2809
|
return [2 /*return*/];
|
|
2804
2810
|
}
|
|
2805
2811
|
});
|