@umituz/react-native-design-system 4.23.113 → 4.23.115
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/package.json +1 -1
- package/src/atoms/AtomicTouchable.tsx +22 -0
- package/src/atoms/badge/AtomicBadge.tsx +26 -28
- package/src/atoms/chip/AtomicChip.tsx +5 -5
- package/src/atoms/datepicker/components/DatePickerModal.tsx +4 -3
- package/src/atoms/input/hooks/useInputState.ts +1 -1
- package/src/atoms/picker/components/PickerModal.tsx +1 -1
- package/src/atoms/picker/hooks/usePickerState.ts +28 -15
- package/src/atoms/skeleton/AtomicSkeleton.tsx +5 -5
- package/src/device/infrastructure/services/DeviceCapabilityService.ts +1 -12
- package/src/filesystem/infrastructure/services/directory.service.ts +37 -9
- package/src/filesystem/infrastructure/services/download.service.ts +62 -11
- package/src/filesystem/infrastructure/services/file-manager.service.ts +42 -11
- package/src/filesystem/infrastructure/services/file-writer.service.ts +8 -3
- package/src/media/infrastructure/services/MediaPickerService.ts +32 -8
- package/src/media/infrastructure/services/MediaSaveService.ts +7 -2
- package/src/media/presentation/hooks/useMedia.ts +60 -22
- package/src/molecules/BaseModal.tsx +1 -0
- package/src/molecules/ConfirmationModalMain.tsx +1 -0
- package/src/molecules/ListItem.tsx +15 -1
- package/src/molecules/avatar/Avatar.tsx +28 -11
- package/src/molecules/bottom-sheet/components/BottomSheet.tsx +1 -0
- package/src/molecules/calendar/presentation/components/AtomicCalendar.tsx +1 -1
- package/src/responsive/useResponsive.ts +1 -1
- package/src/services/api/ApiClient.ts +37 -6
- package/src/storage/presentation/hooks/usePersistentCache.ts +20 -12
- package/src/storage/presentation/hooks/useStore.ts +1 -0
- package/src/tanstack/presentation/hooks/usePrefetch.ts +14 -0
- package/src/theme/infrastructure/stores/themeStore.ts +13 -11
- package/src/timezone/infrastructure/services/BusinessCalendarManager.ts +1 -0
- package/src/timezone/infrastructure/services/CalendarManager.ts +2 -2
- package/src/timezone/infrastructure/services/DateComparisonUtils.ts +1 -0
- package/src/timezone/infrastructure/services/DateFormatter.ts +3 -2
- package/src/timezone/infrastructure/services/DateRangeUtils.ts +1 -0
- package/src/timezone/infrastructure/utils/TimezoneParsers.ts +27 -0
- package/src/utilities/sharing/presentation/hooks/useSharing.ts +44 -17
- package/src/utils/async/index.ts +12 -0
- package/src/utils/async/retryWithBackoff.ts +177 -0
- package/src/utils/errors/DesignSystemError.ts +117 -0
- package/src/utils/errors/ErrorHandler.ts +137 -0
- package/src/utils/errors/index.ts +7 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ErrorHandler
|
|
3
|
+
*
|
|
4
|
+
* Centralized error handling utility for the design system.
|
|
5
|
+
* Provides consistent error handling, logging, and reporting.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { DesignSystemError, ErrorCodes } from './DesignSystemError';
|
|
9
|
+
|
|
10
|
+
export class ErrorHandler {
|
|
11
|
+
/**
|
|
12
|
+
* Handle and normalize errors
|
|
13
|
+
* Converts any error type to DesignSystemError
|
|
14
|
+
*/
|
|
15
|
+
static handle(
|
|
16
|
+
error: unknown,
|
|
17
|
+
context?: string,
|
|
18
|
+
additionalContext?: Record<string, any>
|
|
19
|
+
): DesignSystemError {
|
|
20
|
+
// Already a DesignSystemError, return as-is
|
|
21
|
+
if (error instanceof DesignSystemError) {
|
|
22
|
+
return error;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Standard Error object
|
|
26
|
+
if (error instanceof Error) {
|
|
27
|
+
return new DesignSystemError(
|
|
28
|
+
error.message,
|
|
29
|
+
ErrorCodes.UNKNOWN_ERROR,
|
|
30
|
+
{
|
|
31
|
+
context,
|
|
32
|
+
originalError: error.name,
|
|
33
|
+
stack: error.stack,
|
|
34
|
+
...additionalContext,
|
|
35
|
+
}
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// String error
|
|
40
|
+
if (typeof error === 'string') {
|
|
41
|
+
return new DesignSystemError(
|
|
42
|
+
error,
|
|
43
|
+
ErrorCodes.UNKNOWN_ERROR,
|
|
44
|
+
{ context, ...additionalContext }
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Unknown error type
|
|
49
|
+
return new DesignSystemError(
|
|
50
|
+
'An unknown error occurred',
|
|
51
|
+
ErrorCodes.UNKNOWN_ERROR,
|
|
52
|
+
{
|
|
53
|
+
context,
|
|
54
|
+
originalError: String(error),
|
|
55
|
+
...additionalContext,
|
|
56
|
+
}
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Log error to console (only in development)
|
|
62
|
+
*/
|
|
63
|
+
static log(error: DesignSystemError | Error | unknown): void {
|
|
64
|
+
if (__DEV__) {
|
|
65
|
+
if (error instanceof DesignSystemError) {
|
|
66
|
+
console.error('[DesignSystemError]', error.toJSON());
|
|
67
|
+
} else if (error instanceof Error) {
|
|
68
|
+
console.error('[Error]', {
|
|
69
|
+
name: error.name,
|
|
70
|
+
message: error.message,
|
|
71
|
+
stack: error.stack,
|
|
72
|
+
});
|
|
73
|
+
} else {
|
|
74
|
+
console.error('[Unknown Error]', error);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Handle error with logging
|
|
81
|
+
* Combines handle() and log() for convenience
|
|
82
|
+
*/
|
|
83
|
+
static handleAndLog(
|
|
84
|
+
error: unknown,
|
|
85
|
+
context?: string,
|
|
86
|
+
additionalContext?: Record<string, any>
|
|
87
|
+
): DesignSystemError {
|
|
88
|
+
const handled = this.handle(error, context, additionalContext);
|
|
89
|
+
this.log(handled);
|
|
90
|
+
return handled;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Create a new DesignSystemError with specific code
|
|
95
|
+
*/
|
|
96
|
+
static create(
|
|
97
|
+
message: string,
|
|
98
|
+
code: string,
|
|
99
|
+
context?: Record<string, any>
|
|
100
|
+
): DesignSystemError {
|
|
101
|
+
return new DesignSystemError(message, code, context);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Wrap async function with error handling
|
|
106
|
+
* Returns [error, result] tuple (similar to Go pattern)
|
|
107
|
+
*/
|
|
108
|
+
static async tryAsync<T>(
|
|
109
|
+
fn: () => Promise<T>,
|
|
110
|
+
context?: string
|
|
111
|
+
): Promise<[DesignSystemError | null, T | null]> {
|
|
112
|
+
try {
|
|
113
|
+
const result = await fn();
|
|
114
|
+
return [null, result];
|
|
115
|
+
} catch (error) {
|
|
116
|
+
const handled = this.handleAndLog(error, context);
|
|
117
|
+
return [handled, null];
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Wrap sync function with error handling
|
|
123
|
+
* Returns [error, result] tuple
|
|
124
|
+
*/
|
|
125
|
+
static try<T>(
|
|
126
|
+
fn: () => T,
|
|
127
|
+
context?: string
|
|
128
|
+
): [DesignSystemError | null, T | null] {
|
|
129
|
+
try {
|
|
130
|
+
const result = fn();
|
|
131
|
+
return [null, result];
|
|
132
|
+
} catch (error) {
|
|
133
|
+
const handled = this.handleAndLog(error, context);
|
|
134
|
+
return [handled, null];
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|