@umituz/react-native-exception 1.0.2 → 1.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/LICENSE +5 -0
- package/README.md +20 -0
- package/package.json +8 -4
- package/src/domain/entities/ExceptionEntity.ts +10 -2
- package/src/domain/repositories/IExceptionRepository.ts +5 -0
- package/src/index.ts +5 -0
- package/src/infrastructure/services/ExceptionService.ts +5 -0
- package/src/infrastructure/storage/ExceptionStore.ts +5 -0
- package/src/presentation/components/EmptyState.tsx +123 -0
- package/src/presentation/components/ErrorBoundary.tsx +1 -1
package/README.md
CHANGED
|
@@ -6,6 +6,7 @@ Exception handling and error tracking for React Native apps.
|
|
|
6
6
|
|
|
7
7
|
- Centralized exception handling
|
|
8
8
|
- Error boundary component
|
|
9
|
+
- Empty state component for no data scenarios
|
|
9
10
|
- Exception store with Zustand
|
|
10
11
|
- Error categorization and severity levels
|
|
11
12
|
- Exception reporting utilities
|
|
@@ -21,6 +22,8 @@ npm install @umituz/react-native-exception
|
|
|
21
22
|
- `react` >= 18.2.0
|
|
22
23
|
- `react-native` >= 0.74.0
|
|
23
24
|
- `zustand` >= 5.0.2
|
|
25
|
+
- `@umituz/react-native-design-system-theme` >= 1.0.0
|
|
26
|
+
- `@umituz/react-native-design-system` >= 1.0.0
|
|
24
27
|
|
|
25
28
|
## Usage
|
|
26
29
|
|
|
@@ -59,6 +62,20 @@ import { useExceptionStore } from '@umituz/react-native-exception';
|
|
|
59
62
|
const { exceptions, lastError } = useExceptionStore();
|
|
60
63
|
```
|
|
61
64
|
|
|
65
|
+
### Empty State
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
import { EmptyState } from '@umituz/react-native-exception';
|
|
69
|
+
|
|
70
|
+
<EmptyState
|
|
71
|
+
icon="inbox"
|
|
72
|
+
title="No items found"
|
|
73
|
+
description="Start by adding your first item"
|
|
74
|
+
actionLabel="Add Item"
|
|
75
|
+
onAction={() => navigation.navigate('Add')}
|
|
76
|
+
/>
|
|
77
|
+
```
|
|
78
|
+
|
|
62
79
|
## License
|
|
63
80
|
|
|
64
81
|
MIT
|
|
@@ -72,3 +89,6 @@ MIT
|
|
|
72
89
|
|
|
73
90
|
|
|
74
91
|
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-exception",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Exception handling and error tracking for React Native apps",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -32,10 +32,13 @@
|
|
|
32
32
|
"react": ">=18.2.0",
|
|
33
33
|
"react-native": ">=0.74.0",
|
|
34
34
|
"zustand": "^5.0.2",
|
|
35
|
-
"
|
|
35
|
+
"uuid": "^9.0.0",
|
|
36
|
+
"react-native-get-random-values": "^1.11.0",
|
|
37
|
+
"@umituz/react-native-design-system-theme": "*",
|
|
38
|
+
"@umituz/react-native-design-system": "*"
|
|
36
39
|
},
|
|
37
40
|
"peerDependenciesMeta": {
|
|
38
|
-
"@umituz/react-native-theme": {
|
|
41
|
+
"@umituz/react-native-design-system-theme": {
|
|
39
42
|
"optional": false
|
|
40
43
|
}
|
|
41
44
|
},
|
|
@@ -46,7 +49,8 @@
|
|
|
46
49
|
"react": "^18.2.0",
|
|
47
50
|
"react-native": "^0.74.0",
|
|
48
51
|
"zustand": "^5.0.2",
|
|
49
|
-
"@umituz/react-native-theme": "latest"
|
|
52
|
+
"@umituz/react-native-design-system-theme": "latest",
|
|
53
|
+
"@umituz/react-native-design-system": "latest"
|
|
50
54
|
},
|
|
51
55
|
"publishConfig": {
|
|
52
56
|
"access": "public"
|
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
* Pure business logic representation of errors and exceptions
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import 'react-native-get-random-values';
|
|
7
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
8
|
+
|
|
6
9
|
export type ExceptionSeverity = 'fatal' | 'error' | 'warning' | 'info';
|
|
7
10
|
export type ExceptionCategory = 'network' | 'validation' | 'authentication' | 'authorization' | 'business-logic' | 'system' | 'storage' | 'unknown';
|
|
8
11
|
|
|
@@ -48,7 +51,7 @@ export function createException(
|
|
|
48
51
|
context: ExceptionContext = {}
|
|
49
52
|
): ExceptionEntity {
|
|
50
53
|
return {
|
|
51
|
-
id:
|
|
54
|
+
id: uuidv4(),
|
|
52
55
|
message: error.message,
|
|
53
56
|
stack: error.stack,
|
|
54
57
|
severity,
|
|
@@ -67,7 +70,7 @@ export function createErrorLog(
|
|
|
67
70
|
exception: ExceptionEntity
|
|
68
71
|
): ErrorLog {
|
|
69
72
|
return {
|
|
70
|
-
id:
|
|
73
|
+
id: uuidv4(),
|
|
71
74
|
exceptionId: exception.id,
|
|
72
75
|
userId: exception.context.userId,
|
|
73
76
|
message: exception.message,
|
|
@@ -106,3 +109,8 @@ export function shouldReportException(exception: ExceptionEntity): boolean {
|
|
|
106
109
|
|
|
107
110
|
|
|
108
111
|
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
package/src/index.ts
CHANGED
|
@@ -48,6 +48,11 @@ export { ExceptionService, exceptionService } from './infrastructure/services/Ex
|
|
|
48
48
|
|
|
49
49
|
// Components
|
|
50
50
|
export { ErrorBoundary } from './presentation/components/ErrorBoundary';
|
|
51
|
+
export { EmptyState } from './presentation/components/EmptyState';
|
|
52
|
+
export type { EmptyStateProps } from './presentation/components/EmptyState';
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
51
56
|
|
|
52
57
|
|
|
53
58
|
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Empty State Component
|
|
3
|
+
* Displays when no data is available
|
|
4
|
+
*
|
|
5
|
+
* Presentation Layer - UI Component
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import React from "react";
|
|
9
|
+
import { View, StyleSheet, TouchableOpacity } from "react-native";
|
|
10
|
+
import {
|
|
11
|
+
useAppDesignTokens,
|
|
12
|
+
AtomicIcon,
|
|
13
|
+
AtomicText,
|
|
14
|
+
STATIC_TOKENS,
|
|
15
|
+
} from "@umituz/react-native-design-system";
|
|
16
|
+
|
|
17
|
+
export interface EmptyStateProps {
|
|
18
|
+
icon?: string;
|
|
19
|
+
title: string;
|
|
20
|
+
description?: string;
|
|
21
|
+
actionLabel?: string;
|
|
22
|
+
onAction?: () => void;
|
|
23
|
+
illustration?: React.ReactNode;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const EmptyState: React.FC<EmptyStateProps> = ({
|
|
27
|
+
icon = "inbox",
|
|
28
|
+
title,
|
|
29
|
+
description,
|
|
30
|
+
actionLabel,
|
|
31
|
+
onAction,
|
|
32
|
+
illustration,
|
|
33
|
+
}) => {
|
|
34
|
+
const tokens = useAppDesignTokens();
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<View style={styles.container}>
|
|
38
|
+
{illustration ? (
|
|
39
|
+
illustration
|
|
40
|
+
) : (
|
|
41
|
+
<View
|
|
42
|
+
style={[
|
|
43
|
+
styles.iconContainer,
|
|
44
|
+
{ backgroundColor: tokens.colors.surface },
|
|
45
|
+
]}
|
|
46
|
+
>
|
|
47
|
+
<AtomicIcon name={icon} size="xxl" color="secondary" />
|
|
48
|
+
</View>
|
|
49
|
+
)}
|
|
50
|
+
|
|
51
|
+
<AtomicText
|
|
52
|
+
type="headlineSmall"
|
|
53
|
+
color="primary"
|
|
54
|
+
style={[styles.title, { textAlign: "center" }]}
|
|
55
|
+
>
|
|
56
|
+
{title}
|
|
57
|
+
</AtomicText>
|
|
58
|
+
|
|
59
|
+
{description && (
|
|
60
|
+
<AtomicText
|
|
61
|
+
type="bodyMedium"
|
|
62
|
+
color="secondary"
|
|
63
|
+
style={[styles.description, { textAlign: "center" }]}
|
|
64
|
+
>
|
|
65
|
+
{description}
|
|
66
|
+
</AtomicText>
|
|
67
|
+
)}
|
|
68
|
+
|
|
69
|
+
{actionLabel && onAction && (
|
|
70
|
+
<TouchableOpacity
|
|
71
|
+
style={[
|
|
72
|
+
styles.actionButton,
|
|
73
|
+
{ backgroundColor: tokens.colors.primary },
|
|
74
|
+
]}
|
|
75
|
+
onPress={onAction}
|
|
76
|
+
activeOpacity={0.8}
|
|
77
|
+
>
|
|
78
|
+
<AtomicText
|
|
79
|
+
type="labelLarge"
|
|
80
|
+
color="onPrimary"
|
|
81
|
+
style={styles.actionButtonText}
|
|
82
|
+
>
|
|
83
|
+
{actionLabel}
|
|
84
|
+
</AtomicText>
|
|
85
|
+
</TouchableOpacity>
|
|
86
|
+
)}
|
|
87
|
+
</View>
|
|
88
|
+
);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const styles = StyleSheet.create({
|
|
92
|
+
container: {
|
|
93
|
+
flex: 1,
|
|
94
|
+
alignItems: "center",
|
|
95
|
+
justifyContent: "center",
|
|
96
|
+
padding: STATIC_TOKENS.spacing.xl,
|
|
97
|
+
},
|
|
98
|
+
iconContainer: {
|
|
99
|
+
width: 120,
|
|
100
|
+
height: 120,
|
|
101
|
+
borderRadius: 60,
|
|
102
|
+
alignItems: "center",
|
|
103
|
+
justifyContent: "center",
|
|
104
|
+
marginBottom: STATIC_TOKENS.spacing.lg,
|
|
105
|
+
},
|
|
106
|
+
title: {
|
|
107
|
+
marginBottom: STATIC_TOKENS.spacing.sm,
|
|
108
|
+
},
|
|
109
|
+
description: {
|
|
110
|
+
marginBottom: STATIC_TOKENS.spacing.lg,
|
|
111
|
+
maxWidth: 280,
|
|
112
|
+
},
|
|
113
|
+
actionButton: {
|
|
114
|
+
paddingHorizontal: STATIC_TOKENS.spacing.lg,
|
|
115
|
+
paddingVertical: STATIC_TOKENS.spacing.md,
|
|
116
|
+
borderRadius: STATIC_TOKENS.borders.radius.md,
|
|
117
|
+
marginTop: STATIC_TOKENS.spacing.sm,
|
|
118
|
+
},
|
|
119
|
+
actionButtonText: {
|
|
120
|
+
// AtomicText handles typography
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import React, { Component, ReactNode } from 'react';
|
|
7
7
|
import { View, Text, StyleSheet, TouchableOpacity } from 'react-native';
|
|
8
8
|
import { exceptionService } from '../../infrastructure/services/ExceptionService';
|
|
9
|
-
import { useAppDesignTokens } from '@umituz/react-native-theme';
|
|
9
|
+
import { useAppDesignTokens } from '@umituz/react-native-design-system-theme';
|
|
10
10
|
|
|
11
11
|
interface Props {
|
|
12
12
|
children: ReactNode;
|