@wrelik/errors 0.2.0 → 2.0.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/.turbo/turbo-build.log +19 -47
- package/CHANGELOG.md +18 -0
- package/dist/{chunk-EARDCOC4.mjs → chunk-SK2GZ7XR.mjs} +30 -7
- package/dist/client/index.d.mts +1 -0
- package/dist/client/index.d.ts +1 -0
- package/dist/client/index.js +70 -0
- package/dist/client/index.mjs +6 -0
- package/dist/server/index.d.mts +13 -0
- package/dist/server/index.d.ts +13 -0
- package/dist/{react-native.js → server/index.js} +38 -47
- package/dist/server/index.mjs +31 -0
- package/dist/shared/index.d.mts +29 -0
- package/dist/shared/index.d.ts +29 -0
- package/dist/{node.js → shared/index.js} +31 -46
- package/dist/shared/index.mjs +16 -0
- package/package.json +27 -12
- package/src/client/index.test.ts +18 -0
- package/src/client/index.ts +2 -0
- package/src/server/index.test.ts +40 -0
- package/src/server/index.ts +26 -0
- package/src/shared/index.test.ts +37 -0
- package/src/shared/index.ts +9 -0
- package/src/shared/types.ts +78 -0
- package/tsconfig.json +3 -2
- package/dist/browser.d.mts +0 -10
- package/dist/browser.d.ts +0 -10
- package/dist/browser.js +0 -115
- package/dist/browser.mjs +0 -40
- package/dist/node.d.mts +0 -10
- package/dist/node.d.ts +0 -10
- package/dist/node.mjs +0 -40
- package/dist/react-native.d.mts +0 -13
- package/dist/react-native.d.ts +0 -13
- package/dist/react-native.mjs +0 -40
- package/dist/shared-DXFP3J32.d.mts +0 -20
- package/dist/shared-DXFP3J32.d.ts +0 -20
- package/src/browser.ts +0 -31
- package/src/node.ts +0 -31
- package/src/react-native.ts +0 -28
- package/src/shared.ts +0 -49
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,56 +1,28 @@
|
|
|
1
1
|
|
|
2
|
-
> @wrelik/errors@
|
|
3
|
-
> tsup src/
|
|
2
|
+
> @wrelik/errors@2.0.0 build /home/runner/work/wrelik-kit/wrelik-kit/packages/errors
|
|
3
|
+
> tsup src/server/index.ts src/client/index.ts src/shared/index.ts --format cjs,esm --dts --clean
|
|
4
4
|
|
|
5
|
-
[34mCLI[39m Building entry: src/
|
|
5
|
+
[34mCLI[39m Building entry: src/client/index.ts, src/server/index.ts, src/shared/index.ts
|
|
6
6
|
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
7
|
[34mCLI[39m tsup v8.5.1
|
|
8
8
|
[34mCLI[39m Target: es2022
|
|
9
9
|
[34mCLI[39m Cleaning output folder
|
|
10
10
|
[34mCJS[39m Build start
|
|
11
11
|
[34mESM[39m Build start
|
|
12
|
-
[
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
[
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
[37m 4 │ "outDir": "dist", [32m"skipLibCheck"[37m: true,
|
|
22
|
-
╵ [32m~~~~~~~~~~~~~~[0m
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
[warn] [33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mDuplicate key "skipLibCheck" in object literal[0m [duplicate-object-key]
|
|
26
|
-
|
|
27
|
-
tsconfig.json:5:4:
|
|
28
|
-
[37m 5 │ [32m"skipLibCheck"[37m: true
|
|
29
|
-
╵ [32m~~~~~~~~~~~~~~[0m
|
|
30
|
-
|
|
31
|
-
The original key "skipLibCheck" is here:
|
|
32
|
-
|
|
33
|
-
tsconfig.json:4:22:
|
|
34
|
-
[37m 4 │ "outDir": "dist", [32m"skipLibCheck"[37m: true,
|
|
35
|
-
╵ [32m~~~~~~~~~~~~~~[0m
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
[32mCJS[39m [1mdist/node.js [22m[32m3.84 KB[39m
|
|
39
|
-
[32mCJS[39m [1mdist/browser.js [22m[32m3.86 KB[39m
|
|
40
|
-
[32mCJS[39m [1mdist/react-native.js [22m[32m3.90 KB[39m
|
|
41
|
-
[32mCJS[39m ⚡️ Build success in 70ms
|
|
42
|
-
[32mESM[39m [1mdist/browser.mjs [22m[32m895.00 B[39m
|
|
43
|
-
[32mESM[39m [1mdist/node.mjs [22m[32m889.00 B[39m
|
|
44
|
-
[32mESM[39m [1mdist/react-native.mjs [22m[32m918.00 B[39m
|
|
45
|
-
[32mESM[39m [1mdist/chunk-EARDCOC4.mjs [22m[32m1.34 KB[39m
|
|
46
|
-
[32mESM[39m ⚡️ Build success in 69ms
|
|
12
|
+
[32mESM[39m [1mdist/server/index.mjs [22m[32m693.00 B[39m
|
|
13
|
+
[32mESM[39m [1mdist/shared/index.mjs [22m[32m287.00 B[39m
|
|
14
|
+
[32mESM[39m [1mdist/client/index.mjs [22m[32m87.00 B[39m
|
|
15
|
+
[32mESM[39m [1mdist/chunk-SK2GZ7XR.mjs [22m[32m1.68 KB[39m
|
|
16
|
+
[32mESM[39m ⚡️ Build success in 66ms
|
|
17
|
+
[32mCJS[39m [1mdist/client/index.js [22m[32m1.96 KB[39m
|
|
18
|
+
[32mCJS[39m [1mdist/server/index.js [22m[32m3.20 KB[39m
|
|
19
|
+
[32mCJS[39m [1mdist/shared/index.js [22m[32m2.91 KB[39m
|
|
20
|
+
[32mCJS[39m ⚡️ Build success in 66ms
|
|
47
21
|
[34mDTS[39m Build start
|
|
48
|
-
[32mDTS[39m ⚡️ Build success in
|
|
49
|
-
[32mDTS[39m [1mdist/
|
|
50
|
-
[32mDTS[39m [1mdist/
|
|
51
|
-
[32mDTS[39m [1mdist/
|
|
52
|
-
[32mDTS[39m [1mdist/
|
|
53
|
-
[32mDTS[39m [1mdist/
|
|
54
|
-
[32mDTS[39m [1mdist/
|
|
55
|
-
[32mDTS[39m [1mdist/react-native.d.mts [22m[32m476.00 B[39m
|
|
56
|
-
[32mDTS[39m [1mdist/shared-DXFP3J32.d.mts [22m[32m851.00 B[39m
|
|
22
|
+
[32mDTS[39m ⚡️ Build success in 9018ms
|
|
23
|
+
[32mDTS[39m [1mdist/server/index.d.ts [22m[32m370.00 B[39m
|
|
24
|
+
[32mDTS[39m [1mdist/shared/index.d.ts [22m[32m1.08 KB[39m
|
|
25
|
+
[32mDTS[39m [1mdist/client/index.d.ts [22m[32m84.00 B[39m
|
|
26
|
+
[32mDTS[39m [1mdist/server/index.d.mts [22m[32m371.00 B[39m
|
|
27
|
+
[32mDTS[39m [1mdist/shared/index.d.mts [22m[32m1.08 KB[39m
|
|
28
|
+
[32mDTS[39m [1mdist/client/index.d.mts [22m[32m85.00 B[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @wrelik/errors
|
|
2
2
|
|
|
3
|
+
## 2.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- 818ed58: Refactor runtime packages to strict subpath exports (`/server`, `/client`, `/shared`) with side-effect free entrypoints and hard CI/runtime boundary enforcement.
|
|
8
|
+
|
|
9
|
+
## 0.2.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 2b9cbf7: Fix auth role checks to reject malformed runtime role payloads and remove a duplicate TypeScript compiler option in errors to eliminate build warnings.
|
|
14
|
+
|
|
15
|
+
## Unreleased
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Remove duplicate `skipLibCheck` key from TypeScript config to eliminate build warnings.
|
|
20
|
+
|
|
3
21
|
## 0.2.0
|
|
4
22
|
|
|
5
23
|
### Minor Changes
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
// src/shared.ts
|
|
1
|
+
// src/shared/types.ts
|
|
2
2
|
var AppError = class extends Error {
|
|
3
3
|
code;
|
|
4
4
|
statusCode;
|
|
5
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6
5
|
context;
|
|
7
6
|
constructor(message, code, statusCode = 500, context) {
|
|
8
7
|
super(message);
|
|
@@ -13,34 +12,58 @@ var AppError = class extends Error {
|
|
|
13
12
|
}
|
|
14
13
|
};
|
|
15
14
|
var AuthRequiredError = class extends AppError {
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
15
|
constructor(message = "Authentication required", context) {
|
|
18
16
|
super(message, "AUTH_REQUIRED", 401, context);
|
|
19
17
|
}
|
|
20
18
|
};
|
|
21
19
|
var TenantRequiredError = class extends AppError {
|
|
22
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
20
|
constructor(message = "Tenant context required", context) {
|
|
24
21
|
super(message, "TENANT_REQUIRED", 400, context);
|
|
25
22
|
}
|
|
26
23
|
};
|
|
27
24
|
var PermissionDeniedError = class extends AppError {
|
|
28
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
25
|
constructor(message = "Permission denied", context) {
|
|
30
26
|
super(message, "PERMISSION_DENIED", 403, context);
|
|
31
27
|
}
|
|
32
28
|
};
|
|
33
29
|
var ValidationError = class extends AppError {
|
|
34
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
35
30
|
constructor(message, context) {
|
|
36
31
|
super(message, "VALIDATION_ERROR", 400, context);
|
|
37
32
|
}
|
|
38
33
|
};
|
|
34
|
+
function normalizeError(err, context) {
|
|
35
|
+
if (err instanceof AppError) {
|
|
36
|
+
return {
|
|
37
|
+
name: err.name,
|
|
38
|
+
message: err.message,
|
|
39
|
+
code: err.code,
|
|
40
|
+
statusCode: err.statusCode,
|
|
41
|
+
context: context ? { ...err.context, ...context } : err.context
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
if (err instanceof Error) {
|
|
45
|
+
return {
|
|
46
|
+
name: err.name,
|
|
47
|
+
message: err.message,
|
|
48
|
+
code: "INTERNAL_ERROR",
|
|
49
|
+
statusCode: 500,
|
|
50
|
+
context
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
name: "Error",
|
|
55
|
+
message: "Unknown error",
|
|
56
|
+
code: "INTERNAL_ERROR",
|
|
57
|
+
statusCode: 500,
|
|
58
|
+
context: context ? { ...context, originalError: err } : { originalError: err }
|
|
59
|
+
};
|
|
60
|
+
}
|
|
39
61
|
|
|
40
62
|
export {
|
|
41
63
|
AppError,
|
|
42
64
|
AuthRequiredError,
|
|
43
65
|
TenantRequiredError,
|
|
44
66
|
PermissionDeniedError,
|
|
45
|
-
ValidationError
|
|
67
|
+
ValidationError,
|
|
68
|
+
normalizeError
|
|
46
69
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ErrorContext, NormalizedError, normalizeError } from '../shared/index.mjs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ErrorContext, NormalizedError, normalizeError } from '../shared/index.js';
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/client/index.ts
|
|
21
|
+
var client_exports = {};
|
|
22
|
+
__export(client_exports, {
|
|
23
|
+
normalizeError: () => normalizeError
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(client_exports);
|
|
26
|
+
|
|
27
|
+
// src/shared/types.ts
|
|
28
|
+
var AppError = class extends Error {
|
|
29
|
+
code;
|
|
30
|
+
statusCode;
|
|
31
|
+
context;
|
|
32
|
+
constructor(message, code, statusCode = 500, context) {
|
|
33
|
+
super(message);
|
|
34
|
+
this.name = "AppError";
|
|
35
|
+
this.code = code;
|
|
36
|
+
this.statusCode = statusCode;
|
|
37
|
+
this.context = context;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
function normalizeError(err, context) {
|
|
41
|
+
if (err instanceof AppError) {
|
|
42
|
+
return {
|
|
43
|
+
name: err.name,
|
|
44
|
+
message: err.message,
|
|
45
|
+
code: err.code,
|
|
46
|
+
statusCode: err.statusCode,
|
|
47
|
+
context: context ? { ...err.context, ...context } : err.context
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
if (err instanceof Error) {
|
|
51
|
+
return {
|
|
52
|
+
name: err.name,
|
|
53
|
+
message: err.message,
|
|
54
|
+
code: "INTERNAL_ERROR",
|
|
55
|
+
statusCode: 500,
|
|
56
|
+
context
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
name: "Error",
|
|
61
|
+
message: "Unknown error",
|
|
62
|
+
code: "INTERNAL_ERROR",
|
|
63
|
+
statusCode: 500,
|
|
64
|
+
context: context ? { ...context, originalError: err } : { originalError: err }
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
68
|
+
0 && (module.exports = {
|
|
69
|
+
normalizeError
|
|
70
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ErrorContext } from '../shared/index.mjs';
|
|
2
|
+
|
|
3
|
+
declare function initErrors(config: {
|
|
4
|
+
dsn: string;
|
|
5
|
+
tracesSampleRate?: number;
|
|
6
|
+
}): void;
|
|
7
|
+
declare function setUserContext(user: {
|
|
8
|
+
id: string;
|
|
9
|
+
email?: string;
|
|
10
|
+
} | null): void;
|
|
11
|
+
declare function captureError(err: unknown, context?: ErrorContext): void;
|
|
12
|
+
|
|
13
|
+
export { captureError, initErrors, setUserContext };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ErrorContext } from '../shared/index.js';
|
|
2
|
+
|
|
3
|
+
declare function initErrors(config: {
|
|
4
|
+
dsn: string;
|
|
5
|
+
tracesSampleRate?: number;
|
|
6
|
+
}): void;
|
|
7
|
+
declare function setUserContext(user: {
|
|
8
|
+
id: string;
|
|
9
|
+
email?: string;
|
|
10
|
+
} | null): void;
|
|
11
|
+
declare function captureError(err: unknown, context?: ErrorContext): void;
|
|
12
|
+
|
|
13
|
+
export { captureError, initErrors, setUserContext };
|
|
@@ -27,26 +27,20 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
|
|
30
|
-
// src/
|
|
31
|
-
var
|
|
32
|
-
__export(
|
|
33
|
-
AppError: () => AppError,
|
|
34
|
-
AuthRequiredError: () => AuthRequiredError,
|
|
35
|
-
PermissionDeniedError: () => PermissionDeniedError,
|
|
36
|
-
TenantRequiredError: () => TenantRequiredError,
|
|
37
|
-
ValidationError: () => ValidationError,
|
|
30
|
+
// src/server/index.ts
|
|
31
|
+
var server_exports = {};
|
|
32
|
+
__export(server_exports, {
|
|
38
33
|
captureError: () => captureError,
|
|
39
34
|
initErrors: () => initErrors,
|
|
40
35
|
setUserContext: () => setUserContext
|
|
41
36
|
});
|
|
42
|
-
module.exports = __toCommonJS(
|
|
43
|
-
var Sentry = __toESM(require("@sentry/
|
|
37
|
+
module.exports = __toCommonJS(server_exports);
|
|
38
|
+
var Sentry = __toESM(require("@sentry/node"));
|
|
44
39
|
|
|
45
|
-
// src/shared.ts
|
|
40
|
+
// src/shared/types.ts
|
|
46
41
|
var AppError = class extends Error {
|
|
47
42
|
code;
|
|
48
43
|
statusCode;
|
|
49
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
50
44
|
context;
|
|
51
45
|
constructor(message, code, statusCode = 500, context) {
|
|
52
46
|
super(message);
|
|
@@ -56,59 +50,56 @@ var AppError = class extends Error {
|
|
|
56
50
|
this.context = context;
|
|
57
51
|
}
|
|
58
52
|
};
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
super(message, "TENANT_REQUIRED", 400, context);
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
var PermissionDeniedError = class extends AppError {
|
|
72
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
73
|
-
constructor(message = "Permission denied", context) {
|
|
74
|
-
super(message, "PERMISSION_DENIED", 403, context);
|
|
53
|
+
function normalizeError(err, context) {
|
|
54
|
+
if (err instanceof AppError) {
|
|
55
|
+
return {
|
|
56
|
+
name: err.name,
|
|
57
|
+
message: err.message,
|
|
58
|
+
code: err.code,
|
|
59
|
+
statusCode: err.statusCode,
|
|
60
|
+
context: context ? { ...err.context, ...context } : err.context
|
|
61
|
+
};
|
|
75
62
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
63
|
+
if (err instanceof Error) {
|
|
64
|
+
return {
|
|
65
|
+
name: err.name,
|
|
66
|
+
message: err.message,
|
|
67
|
+
code: "INTERNAL_ERROR",
|
|
68
|
+
statusCode: 500,
|
|
69
|
+
context
|
|
70
|
+
};
|
|
81
71
|
}
|
|
82
|
-
|
|
72
|
+
return {
|
|
73
|
+
name: "Error",
|
|
74
|
+
message: "Unknown error",
|
|
75
|
+
code: "INTERNAL_ERROR",
|
|
76
|
+
statusCode: 500,
|
|
77
|
+
context: context ? { ...context, originalError: err } : { originalError: err }
|
|
78
|
+
};
|
|
79
|
+
}
|
|
83
80
|
|
|
84
|
-
// src/
|
|
81
|
+
// src/server/index.ts
|
|
85
82
|
function initErrors(config) {
|
|
86
83
|
Sentry.init({
|
|
87
84
|
dsn: config.dsn,
|
|
88
|
-
|
|
85
|
+
tracesSampleRate: config.tracesSampleRate ?? 1
|
|
89
86
|
});
|
|
90
87
|
}
|
|
91
88
|
function setUserContext(user) {
|
|
92
89
|
Sentry.setUser(user);
|
|
93
90
|
}
|
|
94
91
|
function captureError(err, context) {
|
|
92
|
+
const normalized = normalizeError(err, context);
|
|
95
93
|
if (err instanceof AppError) {
|
|
96
|
-
if (
|
|
97
|
-
Sentry.captureException(err, { extra:
|
|
98
|
-
} else {
|
|
99
|
-
console.warn(`[${err.code}] ${err.message}`, { context: err.context, ...context });
|
|
94
|
+
if (normalized.statusCode >= 500) {
|
|
95
|
+
Sentry.captureException(err, { extra: normalized.context });
|
|
100
96
|
}
|
|
101
|
-
|
|
102
|
-
Sentry.captureException(err, { extra: context });
|
|
97
|
+
return;
|
|
103
98
|
}
|
|
99
|
+
Sentry.captureException(err, { extra: normalized.context });
|
|
104
100
|
}
|
|
105
101
|
// Annotate the CommonJS export names for ESM import in node:
|
|
106
102
|
0 && (module.exports = {
|
|
107
|
-
AppError,
|
|
108
|
-
AuthRequiredError,
|
|
109
|
-
PermissionDeniedError,
|
|
110
|
-
TenantRequiredError,
|
|
111
|
-
ValidationError,
|
|
112
103
|
captureError,
|
|
113
104
|
initErrors,
|
|
114
105
|
setUserContext
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AppError,
|
|
3
|
+
normalizeError
|
|
4
|
+
} from "../chunk-SK2GZ7XR.mjs";
|
|
5
|
+
|
|
6
|
+
// src/server/index.ts
|
|
7
|
+
import * as Sentry from "@sentry/node";
|
|
8
|
+
function initErrors(config) {
|
|
9
|
+
Sentry.init({
|
|
10
|
+
dsn: config.dsn,
|
|
11
|
+
tracesSampleRate: config.tracesSampleRate ?? 1
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
function setUserContext(user) {
|
|
15
|
+
Sentry.setUser(user);
|
|
16
|
+
}
|
|
17
|
+
function captureError(err, context) {
|
|
18
|
+
const normalized = normalizeError(err, context);
|
|
19
|
+
if (err instanceof AppError) {
|
|
20
|
+
if (normalized.statusCode >= 500) {
|
|
21
|
+
Sentry.captureException(err, { extra: normalized.context });
|
|
22
|
+
}
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
Sentry.captureException(err, { extra: normalized.context });
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
captureError,
|
|
29
|
+
initErrors,
|
|
30
|
+
setUserContext
|
|
31
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
type ErrorContext = Record<string, any>;
|
|
2
|
+
interface NormalizedError {
|
|
3
|
+
name: string;
|
|
4
|
+
message: string;
|
|
5
|
+
code: string;
|
|
6
|
+
statusCode: number;
|
|
7
|
+
context?: ErrorContext;
|
|
8
|
+
}
|
|
9
|
+
declare class AppError extends Error {
|
|
10
|
+
readonly code: string;
|
|
11
|
+
readonly statusCode: number;
|
|
12
|
+
readonly context?: ErrorContext;
|
|
13
|
+
constructor(message: string, code: string, statusCode?: number, context?: ErrorContext);
|
|
14
|
+
}
|
|
15
|
+
declare class AuthRequiredError extends AppError {
|
|
16
|
+
constructor(message?: string, context?: ErrorContext);
|
|
17
|
+
}
|
|
18
|
+
declare class TenantRequiredError extends AppError {
|
|
19
|
+
constructor(message?: string, context?: ErrorContext);
|
|
20
|
+
}
|
|
21
|
+
declare class PermissionDeniedError extends AppError {
|
|
22
|
+
constructor(message?: string, context?: ErrorContext);
|
|
23
|
+
}
|
|
24
|
+
declare class ValidationError extends AppError {
|
|
25
|
+
constructor(message: string, context?: ErrorContext);
|
|
26
|
+
}
|
|
27
|
+
declare function normalizeError(err: unknown, context?: ErrorContext): NormalizedError;
|
|
28
|
+
|
|
29
|
+
export { AppError, AuthRequiredError, type ErrorContext, type NormalizedError, PermissionDeniedError, TenantRequiredError, ValidationError, normalizeError };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
type ErrorContext = Record<string, any>;
|
|
2
|
+
interface NormalizedError {
|
|
3
|
+
name: string;
|
|
4
|
+
message: string;
|
|
5
|
+
code: string;
|
|
6
|
+
statusCode: number;
|
|
7
|
+
context?: ErrorContext;
|
|
8
|
+
}
|
|
9
|
+
declare class AppError extends Error {
|
|
10
|
+
readonly code: string;
|
|
11
|
+
readonly statusCode: number;
|
|
12
|
+
readonly context?: ErrorContext;
|
|
13
|
+
constructor(message: string, code: string, statusCode?: number, context?: ErrorContext);
|
|
14
|
+
}
|
|
15
|
+
declare class AuthRequiredError extends AppError {
|
|
16
|
+
constructor(message?: string, context?: ErrorContext);
|
|
17
|
+
}
|
|
18
|
+
declare class TenantRequiredError extends AppError {
|
|
19
|
+
constructor(message?: string, context?: ErrorContext);
|
|
20
|
+
}
|
|
21
|
+
declare class PermissionDeniedError extends AppError {
|
|
22
|
+
constructor(message?: string, context?: ErrorContext);
|
|
23
|
+
}
|
|
24
|
+
declare class ValidationError extends AppError {
|
|
25
|
+
constructor(message: string, context?: ErrorContext);
|
|
26
|
+
}
|
|
27
|
+
declare function normalizeError(err: unknown, context?: ErrorContext): NormalizedError;
|
|
28
|
+
|
|
29
|
+
export { AppError, AuthRequiredError, type ErrorContext, type NormalizedError, PermissionDeniedError, TenantRequiredError, ValidationError, normalizeError };
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,36 +15,24 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
|
|
30
|
-
// src/
|
|
31
|
-
var
|
|
32
|
-
__export(
|
|
20
|
+
// src/shared/index.ts
|
|
21
|
+
var shared_exports = {};
|
|
22
|
+
__export(shared_exports, {
|
|
33
23
|
AppError: () => AppError,
|
|
34
24
|
AuthRequiredError: () => AuthRequiredError,
|
|
35
25
|
PermissionDeniedError: () => PermissionDeniedError,
|
|
36
26
|
TenantRequiredError: () => TenantRequiredError,
|
|
37
27
|
ValidationError: () => ValidationError,
|
|
38
|
-
|
|
39
|
-
initErrors: () => initErrors,
|
|
40
|
-
setUserContext: () => setUserContext
|
|
28
|
+
normalizeError: () => normalizeError
|
|
41
29
|
});
|
|
42
|
-
module.exports = __toCommonJS(
|
|
43
|
-
var Sentry = __toESM(require("@sentry/node"));
|
|
30
|
+
module.exports = __toCommonJS(shared_exports);
|
|
44
31
|
|
|
45
|
-
// src/shared.ts
|
|
32
|
+
// src/shared/types.ts
|
|
46
33
|
var AppError = class extends Error {
|
|
47
34
|
code;
|
|
48
35
|
statusCode;
|
|
49
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
50
36
|
context;
|
|
51
37
|
constructor(message, code, statusCode = 500, context) {
|
|
52
38
|
super(message);
|
|
@@ -57,50 +43,51 @@ var AppError = class extends Error {
|
|
|
57
43
|
}
|
|
58
44
|
};
|
|
59
45
|
var AuthRequiredError = class extends AppError {
|
|
60
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
61
46
|
constructor(message = "Authentication required", context) {
|
|
62
47
|
super(message, "AUTH_REQUIRED", 401, context);
|
|
63
48
|
}
|
|
64
49
|
};
|
|
65
50
|
var TenantRequiredError = class extends AppError {
|
|
66
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
67
51
|
constructor(message = "Tenant context required", context) {
|
|
68
52
|
super(message, "TENANT_REQUIRED", 400, context);
|
|
69
53
|
}
|
|
70
54
|
};
|
|
71
55
|
var PermissionDeniedError = class extends AppError {
|
|
72
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
73
56
|
constructor(message = "Permission denied", context) {
|
|
74
57
|
super(message, "PERMISSION_DENIED", 403, context);
|
|
75
58
|
}
|
|
76
59
|
};
|
|
77
60
|
var ValidationError = class extends AppError {
|
|
78
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
79
61
|
constructor(message, context) {
|
|
80
62
|
super(message, "VALIDATION_ERROR", 400, context);
|
|
81
63
|
}
|
|
82
64
|
};
|
|
83
|
-
|
|
84
|
-
// src/node.ts
|
|
85
|
-
function captureError(err, context) {
|
|
65
|
+
function normalizeError(err, context) {
|
|
86
66
|
if (err instanceof AppError) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
67
|
+
return {
|
|
68
|
+
name: err.name,
|
|
69
|
+
message: err.message,
|
|
70
|
+
code: err.code,
|
|
71
|
+
statusCode: err.statusCode,
|
|
72
|
+
context: context ? { ...err.context, ...context } : err.context
|
|
73
|
+
};
|
|
94
74
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
75
|
+
if (err instanceof Error) {
|
|
76
|
+
return {
|
|
77
|
+
name: err.name,
|
|
78
|
+
message: err.message,
|
|
79
|
+
code: "INTERNAL_ERROR",
|
|
80
|
+
statusCode: 500,
|
|
81
|
+
context
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
name: "Error",
|
|
86
|
+
message: "Unknown error",
|
|
87
|
+
code: "INTERNAL_ERROR",
|
|
88
|
+
statusCode: 500,
|
|
89
|
+
context: context ? { ...context, originalError: err } : { originalError: err }
|
|
90
|
+
};
|
|
104
91
|
}
|
|
105
92
|
// Annotate the CommonJS export names for ESM import in node:
|
|
106
93
|
0 && (module.exports = {
|
|
@@ -109,7 +96,5 @@ function initErrors(dsn) {
|
|
|
109
96
|
PermissionDeniedError,
|
|
110
97
|
TenantRequiredError,
|
|
111
98
|
ValidationError,
|
|
112
|
-
|
|
113
|
-
initErrors,
|
|
114
|
-
setUserContext
|
|
99
|
+
normalizeError
|
|
115
100
|
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AppError,
|
|
3
|
+
AuthRequiredError,
|
|
4
|
+
PermissionDeniedError,
|
|
5
|
+
TenantRequiredError,
|
|
6
|
+
ValidationError,
|
|
7
|
+
normalizeError
|
|
8
|
+
} from "../chunk-SK2GZ7XR.mjs";
|
|
9
|
+
export {
|
|
10
|
+
AppError,
|
|
11
|
+
AuthRequiredError,
|
|
12
|
+
PermissionDeniedError,
|
|
13
|
+
TenantRequiredError,
|
|
14
|
+
ValidationError,
|
|
15
|
+
normalizeError
|
|
16
|
+
};
|