create-nova-expo-template
Version:
A template for creating a new React Native app using Expo and TypeScript, with a focus on performance and best practices.
32 lines (30 loc) • 961 B
text/typescript
/* eslint-disable @typescript-eslint/no-explicit-any */
import Toast from "react-native-toast-message";
export default function HandleErrors(err: any) {
const showErrorToast = (msg: string) => {
Toast.show({
type: "error",
text1: "Error",
text2: msg,
});
};
console.log("err=>:", err);
// if (err?.code?.includes("token_not_valid")) {
// store.dispatch(logout());
// }
if (err.details?.reason) {
showErrorToast(err.details?.reason);
} else if (err.message) {
showErrorToast(err.message);
} else if (err.details?.length) {
showErrorToast(err.details.join(", "));
} else if (err.detail) {
showErrorToast(err.detail);
} else if (err && Object.keys(err)) {
showErrorToast(err[Object.keys(err)[0]]);
} else if (Object.keys(err)?.length !== 0) {
showErrorToast(String(Object.values(err)[0]));
} else {
showErrorToast("خطأ غير متوقع!");
}
}