diff --git a/guard_app/src/screen/ShiftDetailsScreen.tsx b/guard_app/src/screen/ShiftDetailsScreen.tsx index 9fd20e1c..33718320 100644 --- a/guard_app/src/screen/ShiftDetailsScreen.tsx +++ b/guard_app/src/screen/ShiftDetailsScreen.tsx @@ -2,6 +2,7 @@ import { Ionicons } from '@expo/vector-icons'; import { RouteProp, useNavigation, useRoute } from '@react-navigation/native'; import { NativeStackNavigationProp } from '@react-navigation/native-stack'; +import { AxiosError } from 'axios'; import React, { useEffect, useState } from 'react'; import { Alert, ScrollView, StyleSheet, Text, TouchableOpacity, View } from 'react-native'; @@ -95,9 +96,14 @@ export default function ShiftDetailsScreen() { } if (route.params.refresh) route.params.refresh(); - } catch (e: any) { + } catch (e: unknown) { setModalVisible(false); - const msg = e?.response?.data?.message ?? e?.message ?? 'Action failed'; + let msg; + if (e instanceof AxiosError) { + msg = e?.response?.data?.message ?? e?.message ?? 'Action failed'; + } else { + msg = 'Action failed'; + } if (typeof msg === 'string' && msg.toLowerCase().includes('location')) { Alert.alert('Location Error', 'You are not at the shift location ❌'); diff --git a/guard_app/src/screen/TimeSheetsScreen.tsx b/guard_app/src/screen/TimeSheetsScreen.tsx index 0304e657..fbbec6fa 100644 --- a/guard_app/src/screen/TimeSheetsScreen.tsx +++ b/guard_app/src/screen/TimeSheetsScreen.tsx @@ -1,5 +1,6 @@ // src/screen/TimesheetsScreen.tsx import { useFocusEffect } from '@react-navigation/native'; +import { AxiosError } from 'axios'; import React, { useCallback, useState } from 'react'; import { View, @@ -28,7 +29,7 @@ function fmtDateTime(d?: string | null) { } function fmtShiftLabel(att: Attendance) { - const s = att.shiftId as any; + const s = att.shiftId; if (s && typeof s === 'object') { const title = s.title ?? 'Shift'; @@ -52,9 +53,13 @@ export default function TimesheetsScreen() { try { const rows = await getMyAttendance(); setItems(rows); - } catch (e: any) { - const msg = e?.response?.data?.message ?? e?.message ?? 'Failed to load timesheets'; - Alert.alert('Error', msg); + } catch (e: unknown) { + if (e instanceof AxiosError) { + const msg = e?.response?.data?.message ?? e?.message ?? 'Failed to load timesheets'; + Alert.alert('Error', msg); + } else { + Alert.alert('Error', 'Failed to load timesheets'); + } } finally { setLoading(false); setRefreshing(false);