@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/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
- }
@@ -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
- }