diff --git a/front/API.ts b/front/API.ts index 4d2d3b7..42e6e04 100644 --- a/front/API.ts +++ b/front/API.ts @@ -72,7 +72,7 @@ export default class API { try { const jsonResponse = body.length != 0 ? JSON.parse(body) : {}; if (!response.ok) { - throw new APIError(jsonResponse ?? response.statusText, response.status); + throw new APIError(response.statusText ?? body, response.status); } return jsonResponse; } catch (e) { diff --git a/front/Navigation.tsx b/front/Navigation.tsx index 653b65f..deb21b2 100644 --- a/front/Navigation.tsx +++ b/front/Navigation.tsx @@ -27,6 +27,7 @@ import ArtistDetailsView from './views/ArtistDetailsView'; import { Button, Center, VStack } from 'native-base'; import { unsetAccessToken } from './state/UserSlice'; import TextButton from './components/TextButton'; +import ErrorView from './views/ErrorView'; const protectedRoutes = () => ({ @@ -64,6 +65,11 @@ const protectedRoutes = () => options: { title: translate('search') }, link: '/search/:query?', }, + Error: { + component: ErrorView, + options: { title: translate('error'), headerLeft: null }, + link: undefined, + }, User: { component: ProfileView, options: { title: translate('user') }, link: '/user' }, } as const); diff --git a/front/i18n/Translations.ts b/front/i18n/Translations.ts index ab83f94..2bb6c76 100644 --- a/front/i18n/Translations.ts +++ b/front/i18n/Translations.ts @@ -1,4 +1,7 @@ export const en = { + error: 'Error', + goBackHome: 'Go Back Home', + anErrorOccured: 'An Error Occured', welcome: 'Welcome', welcomeMessage: 'Welcome back ', signOutBtn: 'Sign out', @@ -179,6 +182,9 @@ export const en = { }; export const fr: typeof en = { + error: 'Erreur', + goBackHome: "Retourner à l'accueil", + anErrorOccured: 'Une Errur est survenue', welcome: 'Bienvenue', welcomeMessage: 'Re-Bonjour ', signOutBtn: 'Se déconnecter', @@ -357,6 +363,9 @@ export const fr: typeof en = { }; export const sp: typeof en = { + error: 'Error', + anErrorOccured: 'ocurrió un error', + goBackHome: 'regresar a casa', welcomeMessage: 'Benvenido', signOutBtn: 'Desconectarse', signInBtn: 'Connectarse', diff --git a/front/views/ArtistDetailsView.tsx b/front/views/ArtistDetailsView.tsx index 77e3b3b..ea59bb0 100644 --- a/front/views/ArtistDetailsView.tsx +++ b/front/views/ArtistDetailsView.tsx @@ -2,8 +2,9 @@ import { VStack, Image, Heading, IconButton, Icon, Container } from 'native-base import { Ionicons } from '@expo/vector-icons'; import { SafeAreaView } from 'react-native'; import { useQuery } from 'react-query'; -import LoadingComponent from '../components/Loading'; +import { LoadingView } from '../components/Loading'; import API from '../API'; +import { useNavigation } from '../Navigation'; const handleFavorite = () => {}; @@ -12,12 +13,19 @@ type ArtistDetailsViewProps = { }; const ArtistDetailsView = ({ artistId }: ArtistDetailsViewProps) => { - const { isLoading, data: artistData } = useQuery(['artist', artistId], () => - API.getArtist(artistId) - ); + const navigation = useNavigation(); + const { + isLoading, + data: artistData, + isError, + } = useQuery(['artist', artistId], () => API.getArtist(artistId)); if (isLoading) { - return ; + return ; + } + + if (isError) { + navigation.navigate('Error'); } return ( diff --git a/front/views/ErrorView.tsx b/front/views/ErrorView.tsx new file mode 100644 index 0000000..0b011c5 --- /dev/null +++ b/front/views/ErrorView.tsx @@ -0,0 +1,19 @@ +import { Button, Center, VStack } from 'native-base'; +import Translate from '../components/Translate'; +import { useNavigation } from '../Navigation'; + +const ErrorView = () => { + const navigation = useNavigation(); + return ( +
+ + + + +
+ ); +}; + +export default ErrorView; diff --git a/front/views/SongLobbyView.tsx b/front/views/SongLobbyView.tsx index 63324ce..a9736a9 100644 --- a/front/views/SongLobbyView.tsx +++ b/front/views/SongLobbyView.tsx @@ -29,6 +29,10 @@ const SongLobbyView = (props: RouteProps) => { }, [chaptersOpen]); useEffect(() => {}, [songQuery.isLoading]); if (songQuery.isLoading || scoresQuery.isLoading) return ; + if (songQuery.isError || scoresQuery.isError) { + navigation.navigate('Error'); + return <>; + } return ( diff --git a/front/views/settings/SettingsView.tsx b/front/views/settings/SettingsView.tsx index 9fc68bd..84f609d 100644 --- a/front/views/settings/SettingsView.tsx +++ b/front/views/settings/SettingsView.tsx @@ -79,7 +79,7 @@ type SetttingsNavigatorProps = { const SetttingsNavigator = (props?: RouteProps) => { const userQuery = useQuery(['user'], () => API.getUserInfo()); const user = useMemo(() => userQuery.data, [userQuery]); - console.log(props?.screen); + if (userQuery.isLoading) { return (