@wrelik/errors 0.2.1 → 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 -21
- package/CHANGELOG.md +6 -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 +2 -1
- 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/src/browser.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
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
|
-
}
|
package/src/react-native.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
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
|
-
}
|
package/src/shared.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2
|
-
export class AppError extends Error {
|
|
3
|
-
public readonly code: string;
|
|
4
|
-
public readonly statusCode: number;
|
|
5
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6
|
-
public readonly context?: Record<string, any>;
|
|
7
|
-
|
|
8
|
-
constructor(
|
|
9
|
-
message: string,
|
|
10
|
-
code: string,
|
|
11
|
-
statusCode: number = 500,
|
|
12
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
|
-
context?: Record<string, any>,
|
|
14
|
-
) {
|
|
15
|
-
super(message);
|
|
16
|
-
this.name = 'AppError';
|
|
17
|
-
this.code = code;
|
|
18
|
-
this.statusCode = statusCode;
|
|
19
|
-
this.context = context;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export class AuthRequiredError extends AppError {
|
|
24
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
|
-
constructor(message = 'Authentication required', context?: Record<string, any>) {
|
|
26
|
-
super(message, 'AUTH_REQUIRED', 401, context);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export class TenantRequiredError extends AppError {
|
|
31
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
|
-
constructor(message = 'Tenant context required', context?: Record<string, any>) {
|
|
33
|
-
super(message, 'TENANT_REQUIRED', 400, context);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export class PermissionDeniedError extends AppError {
|
|
38
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
39
|
-
constructor(message = 'Permission denied', context?: Record<string, any>) {
|
|
40
|
-
super(message, 'PERMISSION_DENIED', 403, context);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export class ValidationError extends AppError {
|
|
45
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
46
|
-
constructor(message: string, context?: Record<string, any>) {
|
|
47
|
-
super(message, 'VALIDATION_ERROR', 400, context);
|
|
48
|
-
}
|
|
49
|
-
}
|