Add centralized error handler for sync Vue app
This commit is contained in:
parent
da90401b2d
commit
01f35b603e
3 changed files with 83 additions and 1 deletions
29
ts/composable/error-handler.ts
Normal file
29
ts/composable/error-handler.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import { ref } from "vue";
|
||||
|
||||
interface ErrorState {
|
||||
hasError: boolean;
|
||||
message: string;
|
||||
timestamp: Date;
|
||||
}
|
||||
|
||||
const globalError = ref<ErrorState | null>(null);
|
||||
|
||||
export function useErrorHandler() {
|
||||
const setError = (error: Error) => {
|
||||
globalError.value = {
|
||||
hasError: true,
|
||||
message: error.message,
|
||||
timestamp: new Date(),
|
||||
};
|
||||
};
|
||||
|
||||
const errorClear = () => {
|
||||
globalError.value = null;
|
||||
};
|
||||
|
||||
return {
|
||||
error: globalError,
|
||||
setError,
|
||||
errorClear,
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue