@umituz/react-native-exception 1.2.6 → 1.2.7
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
CHANGED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exception Repository Interface
|
|
3
|
+
* Defines the contract for exception data persistence
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { ExceptionEntity, ErrorLog } from '../entities/ExceptionEntity';
|
|
7
|
+
|
|
8
|
+
export interface ExceptionRepositoryError {
|
|
9
|
+
code: string;
|
|
10
|
+
message: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type ExceptionResult<T> =
|
|
14
|
+
| { success: true; data: T }
|
|
15
|
+
| { success: false; error: ExceptionRepositoryError };
|
|
16
|
+
|
|
17
|
+
export interface IExceptionRepository {
|
|
18
|
+
/**
|
|
19
|
+
* Save an exception to storage
|
|
20
|
+
*/
|
|
21
|
+
save(exception: ExceptionEntity): Promise<ExceptionResult<void>>;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Get all stored exceptions
|
|
25
|
+
*/
|
|
26
|
+
getAll(): Promise<ExceptionResult<ExceptionEntity[]>>;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Clear all stored exceptions
|
|
30
|
+
*/
|
|
31
|
+
clear(): Promise<ExceptionResult<void>>;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Log an error
|
|
35
|
+
*/
|
|
36
|
+
log(errorLog: ErrorLog): Promise<ExceptionResult<void>>;
|
|
37
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exception Store
|
|
3
|
+
* Zustand store for exception state management
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { create } from 'zustand';
|
|
7
|
+
import type { ExceptionEntity } from '../../domain/entities/ExceptionEntity';
|
|
8
|
+
|
|
9
|
+
interface ExceptionState {
|
|
10
|
+
exceptions: ExceptionEntity[];
|
|
11
|
+
addException: (exception: ExceptionEntity) => void;
|
|
12
|
+
clearExceptions: () => void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const useExceptionStore = create<ExceptionState>((set) => ({
|
|
16
|
+
exceptions: [],
|
|
17
|
+
addException: (exception) =>
|
|
18
|
+
set((state) => ({
|
|
19
|
+
exceptions: [...state.exceptions, exception],
|
|
20
|
+
})),
|
|
21
|
+
clearExceptions: () => set({ exceptions: [] }),
|
|
22
|
+
}));
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Hook to get exceptions from store
|
|
26
|
+
*/
|
|
27
|
+
export const useExceptions = () => {
|
|
28
|
+
const exceptions = useExceptionStore((state) => state.exceptions);
|
|
29
|
+
return exceptions;
|
|
30
|
+
};
|