@wrelik/errors 0.1.0 → 0.2.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 +56 -0
- package/CHANGELOG.md +12 -0
- package/dist/browser.d.mts +10 -0
- package/dist/browser.d.ts +10 -0
- package/dist/browser.js +115 -0
- package/dist/browser.mjs +40 -0
- package/dist/chunk-EARDCOC4.mjs +46 -0
- package/dist/node.d.mts +10 -0
- package/dist/node.d.ts +10 -0
- package/dist/node.js +115 -0
- package/dist/node.mjs +40 -0
- package/dist/react-native.d.mts +13 -0
- package/dist/react-native.d.ts +13 -0
- package/dist/react-native.js +115 -0
- package/dist/react-native.mjs +40 -0
- package/dist/shared-DXFP3J32.d.mts +20 -0
- package/dist/shared-DXFP3J32.d.ts +20 -0
- package/package.json +27 -7
- package/src/browser.ts +31 -0
- package/src/node.ts +31 -0
- package/src/react-native.ts +28 -0
- package/src/{index.ts → shared.ts} +7 -28
- package/tsconfig.json +2 -1
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
|
|
2
|
+
> @wrelik/errors@0.2.0 build /home/runner/work/wrelik-kit/wrelik-kit/packages/errors
|
|
3
|
+
> tsup src/node.ts src/browser.ts src/react-native.ts --format cjs,esm --dts --clean
|
|
4
|
+
|
|
5
|
+
[34mCLI[39m Building entry: src/browser.ts, src/node.ts, src/react-native.ts
|
|
6
|
+
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
|
+
[34mCLI[39m tsup v8.5.1
|
|
8
|
+
[34mCLI[39m Target: es2022
|
|
9
|
+
[34mCLI[39m Cleaning output folder
|
|
10
|
+
[34mCJS[39m Build start
|
|
11
|
+
[34mESM[39m Build start
|
|
12
|
+
[warn] [33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mDuplicate key "skipLibCheck" in object literal[0m [duplicate-object-key]
|
|
13
|
+
|
|
14
|
+
tsconfig.json:5:4:
|
|
15
|
+
[37m 5 │ [32m"skipLibCheck"[37m: true
|
|
16
|
+
╵ [32m~~~~~~~~~~~~~~[0m
|
|
17
|
+
|
|
18
|
+
The original key "skipLibCheck" is here:
|
|
19
|
+
|
|
20
|
+
tsconfig.json:4:22:
|
|
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
|
|
47
|
+
[34mDTS[39m Build start
|
|
48
|
+
[32mDTS[39m ⚡️ Build success in 3543ms
|
|
49
|
+
[32mDTS[39m [1mdist/browser.d.ts [22m[32m432.00 B[39m
|
|
50
|
+
[32mDTS[39m [1mdist/node.d.ts [22m[32m432.00 B[39m
|
|
51
|
+
[32mDTS[39m [1mdist/react-native.d.ts [22m[32m475.00 B[39m
|
|
52
|
+
[32mDTS[39m [1mdist/shared-DXFP3J32.d.ts [22m[32m851.00 B[39m
|
|
53
|
+
[32mDTS[39m [1mdist/browser.d.mts [22m[32m433.00 B[39m
|
|
54
|
+
[32mDTS[39m [1mdist/node.d.mts [22m[32m433.00 B[39m
|
|
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
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @wrelik/errors
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- a38ebcb: Add React Native / Expo support and enforce server-only boundaries.
|
|
8
|
+
|
|
9
|
+
## 0.1.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Update publishConfig to access:public for all packages.
|
|
14
|
+
|
|
3
15
|
## 0.1.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { A as AppError, a as AuthRequiredError, P as PermissionDeniedError, T as TenantRequiredError, V as ValidationError } from './shared-DXFP3J32.mjs';
|
|
2
|
+
|
|
3
|
+
declare function captureError(err: unknown, context?: Record<string, any>): void;
|
|
4
|
+
declare function setUserContext(user: {
|
|
5
|
+
id: string;
|
|
6
|
+
email?: string;
|
|
7
|
+
} | null): void;
|
|
8
|
+
declare function initErrors(dsn: string): void;
|
|
9
|
+
|
|
10
|
+
export { captureError, initErrors, setUserContext };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { A as AppError, a as AuthRequiredError, P as PermissionDeniedError, T as TenantRequiredError, V as ValidationError } from './shared-DXFP3J32.js';
|
|
2
|
+
|
|
3
|
+
declare function captureError(err: unknown, context?: Record<string, any>): void;
|
|
4
|
+
declare function setUserContext(user: {
|
|
5
|
+
id: string;
|
|
6
|
+
email?: string;
|
|
7
|
+
} | null): void;
|
|
8
|
+
declare function initErrors(dsn: string): void;
|
|
9
|
+
|
|
10
|
+
export { captureError, initErrors, setUserContext };
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
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
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/browser.ts
|
|
31
|
+
var browser_exports = {};
|
|
32
|
+
__export(browser_exports, {
|
|
33
|
+
AppError: () => AppError,
|
|
34
|
+
AuthRequiredError: () => AuthRequiredError,
|
|
35
|
+
PermissionDeniedError: () => PermissionDeniedError,
|
|
36
|
+
TenantRequiredError: () => TenantRequiredError,
|
|
37
|
+
ValidationError: () => ValidationError,
|
|
38
|
+
captureError: () => captureError,
|
|
39
|
+
initErrors: () => initErrors,
|
|
40
|
+
setUserContext: () => setUserContext
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(browser_exports);
|
|
43
|
+
var Sentry = __toESM(require("@sentry/browser"));
|
|
44
|
+
|
|
45
|
+
// src/shared.ts
|
|
46
|
+
var AppError = class extends Error {
|
|
47
|
+
code;
|
|
48
|
+
statusCode;
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
50
|
+
context;
|
|
51
|
+
constructor(message, code, statusCode = 500, context) {
|
|
52
|
+
super(message);
|
|
53
|
+
this.name = "AppError";
|
|
54
|
+
this.code = code;
|
|
55
|
+
this.statusCode = statusCode;
|
|
56
|
+
this.context = context;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
var AuthRequiredError = class extends AppError {
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
61
|
+
constructor(message = "Authentication required", context) {
|
|
62
|
+
super(message, "AUTH_REQUIRED", 401, context);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
var TenantRequiredError = class extends AppError {
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
67
|
+
constructor(message = "Tenant context required", context) {
|
|
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);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
var ValidationError = class extends AppError {
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
79
|
+
constructor(message, context) {
|
|
80
|
+
super(message, "VALIDATION_ERROR", 400, context);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// src/browser.ts
|
|
85
|
+
function captureError(err, context) {
|
|
86
|
+
if (err instanceof AppError) {
|
|
87
|
+
console.warn(`[${err.code}] ${err.message}`, { context: err.context, ...context });
|
|
88
|
+
if (err.statusCode >= 500) {
|
|
89
|
+
Sentry.captureException(err, { extra: { ...err.context, ...context } });
|
|
90
|
+
}
|
|
91
|
+
} else {
|
|
92
|
+
console.error("Unexpected error:", err);
|
|
93
|
+
Sentry.captureException(err, { extra: context });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function setUserContext(user) {
|
|
97
|
+
Sentry.setUser(user);
|
|
98
|
+
}
|
|
99
|
+
function initErrors(dsn) {
|
|
100
|
+
Sentry.init({
|
|
101
|
+
dsn,
|
|
102
|
+
tracesSampleRate: 1
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
106
|
+
0 && (module.exports = {
|
|
107
|
+
AppError,
|
|
108
|
+
AuthRequiredError,
|
|
109
|
+
PermissionDeniedError,
|
|
110
|
+
TenantRequiredError,
|
|
111
|
+
ValidationError,
|
|
112
|
+
captureError,
|
|
113
|
+
initErrors,
|
|
114
|
+
setUserContext
|
|
115
|
+
});
|
package/dist/browser.mjs
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AppError,
|
|
3
|
+
AuthRequiredError,
|
|
4
|
+
PermissionDeniedError,
|
|
5
|
+
TenantRequiredError,
|
|
6
|
+
ValidationError
|
|
7
|
+
} from "./chunk-EARDCOC4.mjs";
|
|
8
|
+
|
|
9
|
+
// src/browser.ts
|
|
10
|
+
import * as Sentry from "@sentry/browser";
|
|
11
|
+
function captureError(err, context) {
|
|
12
|
+
if (err instanceof AppError) {
|
|
13
|
+
console.warn(`[${err.code}] ${err.message}`, { context: err.context, ...context });
|
|
14
|
+
if (err.statusCode >= 500) {
|
|
15
|
+
Sentry.captureException(err, { extra: { ...err.context, ...context } });
|
|
16
|
+
}
|
|
17
|
+
} else {
|
|
18
|
+
console.error("Unexpected error:", err);
|
|
19
|
+
Sentry.captureException(err, { extra: context });
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function setUserContext(user) {
|
|
23
|
+
Sentry.setUser(user);
|
|
24
|
+
}
|
|
25
|
+
function initErrors(dsn) {
|
|
26
|
+
Sentry.init({
|
|
27
|
+
dsn,
|
|
28
|
+
tracesSampleRate: 1
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
AppError,
|
|
33
|
+
AuthRequiredError,
|
|
34
|
+
PermissionDeniedError,
|
|
35
|
+
TenantRequiredError,
|
|
36
|
+
ValidationError,
|
|
37
|
+
captureError,
|
|
38
|
+
initErrors,
|
|
39
|
+
setUserContext
|
|
40
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// src/shared.ts
|
|
2
|
+
var AppError = class extends Error {
|
|
3
|
+
code;
|
|
4
|
+
statusCode;
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6
|
+
context;
|
|
7
|
+
constructor(message, code, statusCode = 500, context) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = "AppError";
|
|
10
|
+
this.code = code;
|
|
11
|
+
this.statusCode = statusCode;
|
|
12
|
+
this.context = context;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
var AuthRequiredError = class extends AppError {
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
|
+
constructor(message = "Authentication required", context) {
|
|
18
|
+
super(message, "AUTH_REQUIRED", 401, context);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
var TenantRequiredError = class extends AppError {
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
|
+
constructor(message = "Tenant context required", context) {
|
|
24
|
+
super(message, "TENANT_REQUIRED", 400, context);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var PermissionDeniedError = class extends AppError {
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
|
+
constructor(message = "Permission denied", context) {
|
|
30
|
+
super(message, "PERMISSION_DENIED", 403, context);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var ValidationError = class extends AppError {
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
35
|
+
constructor(message, context) {
|
|
36
|
+
super(message, "VALIDATION_ERROR", 400, context);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export {
|
|
41
|
+
AppError,
|
|
42
|
+
AuthRequiredError,
|
|
43
|
+
TenantRequiredError,
|
|
44
|
+
PermissionDeniedError,
|
|
45
|
+
ValidationError
|
|
46
|
+
};
|
package/dist/node.d.mts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { A as AppError, a as AuthRequiredError, P as PermissionDeniedError, T as TenantRequiredError, V as ValidationError } from './shared-DXFP3J32.mjs';
|
|
2
|
+
|
|
3
|
+
declare function captureError(err: unknown, context?: Record<string, any>): void;
|
|
4
|
+
declare function setUserContext(user: {
|
|
5
|
+
id: string;
|
|
6
|
+
email?: string;
|
|
7
|
+
} | null): void;
|
|
8
|
+
declare function initErrors(dsn: string): void;
|
|
9
|
+
|
|
10
|
+
export { captureError, initErrors, setUserContext };
|
package/dist/node.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { A as AppError, a as AuthRequiredError, P as PermissionDeniedError, T as TenantRequiredError, V as ValidationError } from './shared-DXFP3J32.js';
|
|
2
|
+
|
|
3
|
+
declare function captureError(err: unknown, context?: Record<string, any>): void;
|
|
4
|
+
declare function setUserContext(user: {
|
|
5
|
+
id: string;
|
|
6
|
+
email?: string;
|
|
7
|
+
} | null): void;
|
|
8
|
+
declare function initErrors(dsn: string): void;
|
|
9
|
+
|
|
10
|
+
export { captureError, initErrors, setUserContext };
|
package/dist/node.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
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
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/node.ts
|
|
31
|
+
var node_exports = {};
|
|
32
|
+
__export(node_exports, {
|
|
33
|
+
AppError: () => AppError,
|
|
34
|
+
AuthRequiredError: () => AuthRequiredError,
|
|
35
|
+
PermissionDeniedError: () => PermissionDeniedError,
|
|
36
|
+
TenantRequiredError: () => TenantRequiredError,
|
|
37
|
+
ValidationError: () => ValidationError,
|
|
38
|
+
captureError: () => captureError,
|
|
39
|
+
initErrors: () => initErrors,
|
|
40
|
+
setUserContext: () => setUserContext
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(node_exports);
|
|
43
|
+
var Sentry = __toESM(require("@sentry/node"));
|
|
44
|
+
|
|
45
|
+
// src/shared.ts
|
|
46
|
+
var AppError = class extends Error {
|
|
47
|
+
code;
|
|
48
|
+
statusCode;
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
50
|
+
context;
|
|
51
|
+
constructor(message, code, statusCode = 500, context) {
|
|
52
|
+
super(message);
|
|
53
|
+
this.name = "AppError";
|
|
54
|
+
this.code = code;
|
|
55
|
+
this.statusCode = statusCode;
|
|
56
|
+
this.context = context;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
var AuthRequiredError = class extends AppError {
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
61
|
+
constructor(message = "Authentication required", context) {
|
|
62
|
+
super(message, "AUTH_REQUIRED", 401, context);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
var TenantRequiredError = class extends AppError {
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
67
|
+
constructor(message = "Tenant context required", context) {
|
|
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);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
var ValidationError = class extends AppError {
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
79
|
+
constructor(message, context) {
|
|
80
|
+
super(message, "VALIDATION_ERROR", 400, context);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// src/node.ts
|
|
85
|
+
function captureError(err, context) {
|
|
86
|
+
if (err instanceof AppError) {
|
|
87
|
+
console.warn(`[${err.code}] ${err.message}`, { context: err.context, ...context });
|
|
88
|
+
if (err.statusCode >= 500) {
|
|
89
|
+
Sentry.captureException(err, { extra: { ...err.context, ...context } });
|
|
90
|
+
}
|
|
91
|
+
} else {
|
|
92
|
+
console.error("Unexpected error:", err);
|
|
93
|
+
Sentry.captureException(err, { extra: context });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function setUserContext(user) {
|
|
97
|
+
Sentry.setUser(user);
|
|
98
|
+
}
|
|
99
|
+
function initErrors(dsn) {
|
|
100
|
+
Sentry.init({
|
|
101
|
+
dsn,
|
|
102
|
+
tracesSampleRate: 1
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
106
|
+
0 && (module.exports = {
|
|
107
|
+
AppError,
|
|
108
|
+
AuthRequiredError,
|
|
109
|
+
PermissionDeniedError,
|
|
110
|
+
TenantRequiredError,
|
|
111
|
+
ValidationError,
|
|
112
|
+
captureError,
|
|
113
|
+
initErrors,
|
|
114
|
+
setUserContext
|
|
115
|
+
});
|
package/dist/node.mjs
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AppError,
|
|
3
|
+
AuthRequiredError,
|
|
4
|
+
PermissionDeniedError,
|
|
5
|
+
TenantRequiredError,
|
|
6
|
+
ValidationError
|
|
7
|
+
} from "./chunk-EARDCOC4.mjs";
|
|
8
|
+
|
|
9
|
+
// src/node.ts
|
|
10
|
+
import * as Sentry from "@sentry/node";
|
|
11
|
+
function captureError(err, context) {
|
|
12
|
+
if (err instanceof AppError) {
|
|
13
|
+
console.warn(`[${err.code}] ${err.message}`, { context: err.context, ...context });
|
|
14
|
+
if (err.statusCode >= 500) {
|
|
15
|
+
Sentry.captureException(err, { extra: { ...err.context, ...context } });
|
|
16
|
+
}
|
|
17
|
+
} else {
|
|
18
|
+
console.error("Unexpected error:", err);
|
|
19
|
+
Sentry.captureException(err, { extra: context });
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function setUserContext(user) {
|
|
23
|
+
Sentry.setUser(user);
|
|
24
|
+
}
|
|
25
|
+
function initErrors(dsn) {
|
|
26
|
+
Sentry.init({
|
|
27
|
+
dsn,
|
|
28
|
+
tracesSampleRate: 1
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
AppError,
|
|
33
|
+
AuthRequiredError,
|
|
34
|
+
PermissionDeniedError,
|
|
35
|
+
TenantRequiredError,
|
|
36
|
+
ValidationError,
|
|
37
|
+
captureError,
|
|
38
|
+
initErrors,
|
|
39
|
+
setUserContext
|
|
40
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { A as AppError, a as AuthRequiredError, P as PermissionDeniedError, T as TenantRequiredError, V as ValidationError } from './shared-DXFP3J32.mjs';
|
|
2
|
+
|
|
3
|
+
declare function initErrors(config: {
|
|
4
|
+
dsn: string;
|
|
5
|
+
environment?: string;
|
|
6
|
+
}): void;
|
|
7
|
+
declare function setUserContext(user: {
|
|
8
|
+
id: string;
|
|
9
|
+
email?: string;
|
|
10
|
+
} | null): void;
|
|
11
|
+
declare function captureError(err: unknown, context?: Record<string, any>): void;
|
|
12
|
+
|
|
13
|
+
export { captureError, initErrors, setUserContext };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { A as AppError, a as AuthRequiredError, P as PermissionDeniedError, T as TenantRequiredError, V as ValidationError } from './shared-DXFP3J32.js';
|
|
2
|
+
|
|
3
|
+
declare function initErrors(config: {
|
|
4
|
+
dsn: string;
|
|
5
|
+
environment?: string;
|
|
6
|
+
}): void;
|
|
7
|
+
declare function setUserContext(user: {
|
|
8
|
+
id: string;
|
|
9
|
+
email?: string;
|
|
10
|
+
} | null): void;
|
|
11
|
+
declare function captureError(err: unknown, context?: Record<string, any>): void;
|
|
12
|
+
|
|
13
|
+
export { captureError, initErrors, setUserContext };
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
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
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/react-native.ts
|
|
31
|
+
var react_native_exports = {};
|
|
32
|
+
__export(react_native_exports, {
|
|
33
|
+
AppError: () => AppError,
|
|
34
|
+
AuthRequiredError: () => AuthRequiredError,
|
|
35
|
+
PermissionDeniedError: () => PermissionDeniedError,
|
|
36
|
+
TenantRequiredError: () => TenantRequiredError,
|
|
37
|
+
ValidationError: () => ValidationError,
|
|
38
|
+
captureError: () => captureError,
|
|
39
|
+
initErrors: () => initErrors,
|
|
40
|
+
setUserContext: () => setUserContext
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(react_native_exports);
|
|
43
|
+
var Sentry = __toESM(require("@sentry/react-native"));
|
|
44
|
+
|
|
45
|
+
// src/shared.ts
|
|
46
|
+
var AppError = class extends Error {
|
|
47
|
+
code;
|
|
48
|
+
statusCode;
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
50
|
+
context;
|
|
51
|
+
constructor(message, code, statusCode = 500, context) {
|
|
52
|
+
super(message);
|
|
53
|
+
this.name = "AppError";
|
|
54
|
+
this.code = code;
|
|
55
|
+
this.statusCode = statusCode;
|
|
56
|
+
this.context = context;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
var AuthRequiredError = class extends AppError {
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
61
|
+
constructor(message = "Authentication required", context) {
|
|
62
|
+
super(message, "AUTH_REQUIRED", 401, context);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
var TenantRequiredError = class extends AppError {
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
67
|
+
constructor(message = "Tenant context required", context) {
|
|
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);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
var ValidationError = class extends AppError {
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
79
|
+
constructor(message, context) {
|
|
80
|
+
super(message, "VALIDATION_ERROR", 400, context);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// src/react-native.ts
|
|
85
|
+
function initErrors(config) {
|
|
86
|
+
Sentry.init({
|
|
87
|
+
dsn: config.dsn,
|
|
88
|
+
environment: config.environment || "production"
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
function setUserContext(user) {
|
|
92
|
+
Sentry.setUser(user);
|
|
93
|
+
}
|
|
94
|
+
function captureError(err, context) {
|
|
95
|
+
if (err instanceof AppError) {
|
|
96
|
+
if (err.statusCode >= 500) {
|
|
97
|
+
Sentry.captureException(err, { extra: { ...err.context, ...context } });
|
|
98
|
+
} else {
|
|
99
|
+
console.warn(`[${err.code}] ${err.message}`, { context: err.context, ...context });
|
|
100
|
+
}
|
|
101
|
+
} else {
|
|
102
|
+
Sentry.captureException(err, { extra: context });
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
106
|
+
0 && (module.exports = {
|
|
107
|
+
AppError,
|
|
108
|
+
AuthRequiredError,
|
|
109
|
+
PermissionDeniedError,
|
|
110
|
+
TenantRequiredError,
|
|
111
|
+
ValidationError,
|
|
112
|
+
captureError,
|
|
113
|
+
initErrors,
|
|
114
|
+
setUserContext
|
|
115
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AppError,
|
|
3
|
+
AuthRequiredError,
|
|
4
|
+
PermissionDeniedError,
|
|
5
|
+
TenantRequiredError,
|
|
6
|
+
ValidationError
|
|
7
|
+
} from "./chunk-EARDCOC4.mjs";
|
|
8
|
+
|
|
9
|
+
// src/react-native.ts
|
|
10
|
+
import * as Sentry from "@sentry/react-native";
|
|
11
|
+
function initErrors(config) {
|
|
12
|
+
Sentry.init({
|
|
13
|
+
dsn: config.dsn,
|
|
14
|
+
environment: config.environment || "production"
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
function setUserContext(user) {
|
|
18
|
+
Sentry.setUser(user);
|
|
19
|
+
}
|
|
20
|
+
function captureError(err, context) {
|
|
21
|
+
if (err instanceof AppError) {
|
|
22
|
+
if (err.statusCode >= 500) {
|
|
23
|
+
Sentry.captureException(err, { extra: { ...err.context, ...context } });
|
|
24
|
+
} else {
|
|
25
|
+
console.warn(`[${err.code}] ${err.message}`, { context: err.context, ...context });
|
|
26
|
+
}
|
|
27
|
+
} else {
|
|
28
|
+
Sentry.captureException(err, { extra: context });
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
AppError,
|
|
33
|
+
AuthRequiredError,
|
|
34
|
+
PermissionDeniedError,
|
|
35
|
+
TenantRequiredError,
|
|
36
|
+
ValidationError,
|
|
37
|
+
captureError,
|
|
38
|
+
initErrors,
|
|
39
|
+
setUserContext
|
|
40
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
declare class AppError extends Error {
|
|
2
|
+
readonly code: string;
|
|
3
|
+
readonly statusCode: number;
|
|
4
|
+
readonly context?: Record<string, any>;
|
|
5
|
+
constructor(message: string, code: string, statusCode?: number, context?: Record<string, any>);
|
|
6
|
+
}
|
|
7
|
+
declare class AuthRequiredError extends AppError {
|
|
8
|
+
constructor(message?: string, context?: Record<string, any>);
|
|
9
|
+
}
|
|
10
|
+
declare class TenantRequiredError extends AppError {
|
|
11
|
+
constructor(message?: string, context?: Record<string, any>);
|
|
12
|
+
}
|
|
13
|
+
declare class PermissionDeniedError extends AppError {
|
|
14
|
+
constructor(message?: string, context?: Record<string, any>);
|
|
15
|
+
}
|
|
16
|
+
declare class ValidationError extends AppError {
|
|
17
|
+
constructor(message: string, context?: Record<string, any>);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { AppError as A, PermissionDeniedError as P, TenantRequiredError as T, ValidationError as V, AuthRequiredError as a };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
declare class AppError extends Error {
|
|
2
|
+
readonly code: string;
|
|
3
|
+
readonly statusCode: number;
|
|
4
|
+
readonly context?: Record<string, any>;
|
|
5
|
+
constructor(message: string, code: string, statusCode?: number, context?: Record<string, any>);
|
|
6
|
+
}
|
|
7
|
+
declare class AuthRequiredError extends AppError {
|
|
8
|
+
constructor(message?: string, context?: Record<string, any>);
|
|
9
|
+
}
|
|
10
|
+
declare class TenantRequiredError extends AppError {
|
|
11
|
+
constructor(message?: string, context?: Record<string, any>);
|
|
12
|
+
}
|
|
13
|
+
declare class PermissionDeniedError extends AppError {
|
|
14
|
+
constructor(message?: string, context?: Record<string, any>);
|
|
15
|
+
}
|
|
16
|
+
declare class ValidationError extends AppError {
|
|
17
|
+
constructor(message: string, context?: Record<string, any>);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { AppError as A, PermissionDeniedError as P, TenantRequiredError as T, ValidationError as V, AuthRequiredError as a };
|
package/package.json
CHANGED
|
@@ -1,19 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wrelik/errors",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/lwhite702/wrelik-kit.git",
|
|
10
|
+
"directory": "packages/errors"
|
|
11
|
+
},
|
|
12
|
+
"main": "./dist/node.js",
|
|
13
|
+
"types": "./dist/node.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"react-native": "./dist/react-native.js",
|
|
17
|
+
"browser": "./dist/browser.js",
|
|
18
|
+
"import": "./dist/node.js",
|
|
19
|
+
"require": "./dist/node.js"
|
|
20
|
+
},
|
|
21
|
+
"./react-native": "./dist/react-native.js"
|
|
22
|
+
},
|
|
6
23
|
"dependencies": {
|
|
7
|
-
"@sentry/
|
|
24
|
+
"@sentry/browser": "^10.38.0",
|
|
25
|
+
"@sentry/node": "^7.101.1",
|
|
26
|
+
"@sentry/react-native": "^5.19.0"
|
|
8
27
|
},
|
|
9
28
|
"devDependencies": {
|
|
29
|
+
"@types/node": "^25.2.0",
|
|
10
30
|
"tsup": "^8.0.1",
|
|
11
31
|
"vitest": "^1.2.2",
|
|
12
|
-
"@wrelik/eslint-config": "0.1.
|
|
13
|
-
"@wrelik/tsconfig": "0.1.
|
|
32
|
+
"@wrelik/eslint-config": "0.1.1",
|
|
33
|
+
"@wrelik/tsconfig": "0.1.1"
|
|
14
34
|
},
|
|
15
35
|
"scripts": {
|
|
16
|
-
"build": "tsup src/
|
|
36
|
+
"build": "tsup src/node.ts src/browser.ts src/react-native.ts --format cjs,esm --dts --clean",
|
|
17
37
|
"lint": "eslint src/",
|
|
18
38
|
"test": "vitest run --passWithNoTests"
|
|
19
39
|
}
|
package/src/browser.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as Sentry from '@sentry/browser';
|
|
2
|
+
import { AppError } from './shared';
|
|
3
|
+
|
|
4
|
+
export * from './shared';
|
|
5
|
+
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
|
+
export function captureError(err: unknown, context?: Record<string, any>) {
|
|
8
|
+
if (err instanceof AppError) {
|
|
9
|
+
// Basic logging for expected app errors
|
|
10
|
+
console.warn(`[${err.code}] ${err.message}`, { context: err.context, ...context });
|
|
11
|
+
// Still capture if it's 500 or critical? Maybe optional.
|
|
12
|
+
if (err.statusCode >= 500) {
|
|
13
|
+
Sentry.captureException(err, { extra: { ...err.context, ...context } });
|
|
14
|
+
}
|
|
15
|
+
} else {
|
|
16
|
+
// Unexpected errors
|
|
17
|
+
console.error('Unexpected error:', err);
|
|
18
|
+
Sentry.captureException(err, { extra: context });
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function setUserContext(user: { id: string; email?: string } | null) {
|
|
23
|
+
Sentry.setUser(user);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function initErrors(dsn: string) {
|
|
27
|
+
Sentry.init({
|
|
28
|
+
dsn,
|
|
29
|
+
tracesSampleRate: 1.0,
|
|
30
|
+
});
|
|
31
|
+
}
|
package/src/node.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as Sentry from '@sentry/node';
|
|
2
|
+
import { AppError } from './shared';
|
|
3
|
+
|
|
4
|
+
export * from './shared';
|
|
5
|
+
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
|
+
export function captureError(err: unknown, context?: Record<string, any>) {
|
|
8
|
+
if (err instanceof AppError) {
|
|
9
|
+
// Basic logging for expected app errors
|
|
10
|
+
console.warn(`[${err.code}] ${err.message}`, { context: err.context, ...context });
|
|
11
|
+
// Still capture if it's 500 or critical? Maybe optional.
|
|
12
|
+
if (err.statusCode >= 500) {
|
|
13
|
+
Sentry.captureException(err, { extra: { ...err.context, ...context } });
|
|
14
|
+
}
|
|
15
|
+
} else {
|
|
16
|
+
// Unexpected errors
|
|
17
|
+
console.error('Unexpected error:', err);
|
|
18
|
+
Sentry.captureException(err, { extra: context });
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function setUserContext(user: { id: string; email?: string } | null) {
|
|
23
|
+
Sentry.setUser(user);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function initErrors(dsn: string) {
|
|
27
|
+
Sentry.init({
|
|
28
|
+
dsn,
|
|
29
|
+
tracesSampleRate: 1.0,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as Sentry from '@sentry/react-native';
|
|
2
|
+
import { AppError } from './shared';
|
|
3
|
+
|
|
4
|
+
export * from './shared';
|
|
5
|
+
|
|
6
|
+
export function initErrors(config: { dsn: string; environment?: string }) {
|
|
7
|
+
Sentry.init({
|
|
8
|
+
dsn: config.dsn,
|
|
9
|
+
environment: config.environment || 'production',
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function setUserContext(user: { id: string; email?: string } | null) {
|
|
14
|
+
Sentry.setUser(user);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
+
export function captureError(err: unknown, context?: Record<string, any>) {
|
|
19
|
+
if (err instanceof AppError) {
|
|
20
|
+
if (err.statusCode >= 500) {
|
|
21
|
+
Sentry.captureException(err, { extra: { ...err.context, ...context } });
|
|
22
|
+
} else {
|
|
23
|
+
console.warn(`[${err.code}] ${err.message}`, { context: err.context, ...context });
|
|
24
|
+
}
|
|
25
|
+
} else {
|
|
26
|
+
Sentry.captureException(err, { extra: context });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3
2
|
export class AppError extends Error {
|
|
4
3
|
public readonly code: string;
|
|
5
4
|
public readonly statusCode: number;
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6
6
|
public readonly context?: Record<string, any>;
|
|
7
7
|
|
|
8
8
|
constructor(
|
|
9
9
|
message: string,
|
|
10
10
|
code: string,
|
|
11
11
|
statusCode: number = 500,
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
13
|
context?: Record<string, any>,
|
|
13
14
|
) {
|
|
14
15
|
super(message);
|
|
@@ -20,51 +21,29 @@ export class AppError extends Error {
|
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
export class AuthRequiredError extends AppError {
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
25
|
constructor(message = 'Authentication required', context?: Record<string, any>) {
|
|
24
26
|
super(message, 'AUTH_REQUIRED', 401, context);
|
|
25
27
|
}
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
export class TenantRequiredError extends AppError {
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
32
|
constructor(message = 'Tenant context required', context?: Record<string, any>) {
|
|
30
33
|
super(message, 'TENANT_REQUIRED', 400, context);
|
|
31
34
|
}
|
|
32
35
|
}
|
|
33
36
|
|
|
34
37
|
export class PermissionDeniedError extends AppError {
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
35
39
|
constructor(message = 'Permission denied', context?: Record<string, any>) {
|
|
36
40
|
super(message, 'PERMISSION_DENIED', 403, context);
|
|
37
41
|
}
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
export class ValidationError extends AppError {
|
|
45
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
41
46
|
constructor(message: string, context?: Record<string, any>) {
|
|
42
47
|
super(message, 'VALIDATION_ERROR', 400, context);
|
|
43
48
|
}
|
|
44
49
|
}
|
|
45
|
-
|
|
46
|
-
export function captureError(err: unknown, context?: Record<string, any>) {
|
|
47
|
-
if (err instanceof AppError) {
|
|
48
|
-
// Basic logging for expected app errors
|
|
49
|
-
console.warn(`[${err.code}] ${err.message}`, { context: err.context, ...context });
|
|
50
|
-
// Still capture if it's 500 or critical? Maybe optional.
|
|
51
|
-
if (err.statusCode >= 500) {
|
|
52
|
-
Sentry.captureException(err, { extra: { ...err.context, ...context } });
|
|
53
|
-
}
|
|
54
|
-
} else {
|
|
55
|
-
// Unexpected errors
|
|
56
|
-
console.error('Unexpected error:', err);
|
|
57
|
-
Sentry.captureException(err, { extra: context });
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export function setUserContext(user: { id: string; email?: string } | null) {
|
|
62
|
-
Sentry.setUser(user);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export function initErrors(dsn: string) {
|
|
66
|
-
Sentry.init({
|
|
67
|
-
dsn,
|
|
68
|
-
tracesSampleRate: 1.0,
|
|
69
|
-
});
|
|
70
|
-
}
|