Skip to content

Commit d20eb7a

Browse files
authored
Merge pull request #823 from Sim-sat/no-explicit-any
fix(lint): remove first batch of explicit anys
2 parents 3224f94 + c6b29b1 commit d20eb7a

23 files changed

Lines changed: 153 additions & 146 deletions

SparkyFitnessFrontend/src/api/Chatbot/Chatbot_ExerciseHandler.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ export const processExerciseInput = async (
4747
method: 'GET',
4848
}
4949
);
50-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
51-
} catch (err: any) {
50+
} catch (err: unknown) {
5251
searchError = err; // Assign error to searchError
5352
error(
5453
userLoggingLevel,
@@ -96,8 +95,7 @@ export const processExerciseInput = async (
9695
body: formData,
9796
isFormData: true,
9897
});
99-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
100-
} catch (err: any) {
98+
} catch (err: unknown) {
10199
error(
102100
userLoggingLevel,
103101
'❌ [Nutrition Coach] Error creating exercise:',
@@ -131,8 +129,7 @@ export const processExerciseInput = async (
131129
: undefined,
132130
},
133131
});
134-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
135-
} catch (err: any) {
132+
} catch (err: unknown) {
136133
error(
137134
userLoggingLevel,
138135
'❌ [Nutrition Coach] Error adding exercise entry:',

SparkyFitnessFrontend/src/api/Chatbot/Chatbot_FoodHandler.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ export const processFoodInput = async (
107107
method: 'GET',
108108
}
109109
);
110-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
111-
} catch (err: any) {
110+
} catch (err: unknown) {
112111
error(
113112
userLoggingLevel,
114113
'❌ [Nutrition Coach] Error searching for exact food match:',
@@ -136,8 +135,7 @@ export const processFoodInput = async (
136135
method: 'GET',
137136
}
138137
);
139-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
140-
} catch (err: any) {
138+
} catch (err: unknown) {
141139
error(
142140
userLoggingLevel,
143141
'❌ [Nutrition Coach] Error searching for broad food match:',
@@ -197,8 +195,7 @@ export const processFoodInput = async (
197195
variant_id: food.default_variant.id, // Populate variant_id
198196
},
199197
});
200-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
201-
} catch (err: any) {
198+
} catch (err: unknown) {
202199
error(
203200
userLoggingLevel,
204201
'❌ [Nutrition Coach] Error adding food entry:',
@@ -301,8 +298,7 @@ export const addFoodOption = async (
301298
method: 'GET',
302299
}
303300
);
304-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
305-
} catch (err: any) {
301+
} catch (err: unknown) {
306302
error(
307303
userLoggingLevel,
308304
`[${transactionId}] Error fetching existing food:`,
@@ -340,8 +336,7 @@ export const addFoodOption = async (
340336
method: 'GET',
341337
}
342338
);
343-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
344-
} catch (err: any) {
339+
} catch (err: unknown) {
345340
error(
346341
userLoggingLevel,
347342
`[${transactionId}] Error fetching existing variant:`,
@@ -396,8 +391,7 @@ export const addFoodOption = async (
396391
iron: selectedOption.iron,
397392
},
398393
});
399-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
400-
} catch (err: any) {
394+
} catch (err: unknown) {
401395
error(
402396
userLoggingLevel,
403397
`[${transactionId}] Error creating food variant:`,
@@ -447,8 +441,7 @@ export const addFoodOption = async (
447441
is_custom: true,
448442
},
449443
});
450-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
451-
} catch (err: any) {
444+
} catch (err: unknown) {
452445
error(userLoggingLevel, `[${transactionId}] Error creating food:`, err);
453446
return {
454447
action: 'none',
@@ -485,8 +478,7 @@ export const addFoodOption = async (
485478
variant_id: variantId,
486479
},
487480
});
488-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
489-
} catch (err: any) {
481+
} catch (err: unknown) {
490482
error(
491483
userLoggingLevel,
492484
`[${transactionId}] Error creating food entry:`,

SparkyFitnessFrontend/src/api/Chatbot/Chatbot_MeasurementHandler.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
type UserLoggingLevel,
88
} from '@/utils/logging';
99
import { apiCall } from '@/api/api';
10+
import { getErrorMessage } from '@/utils/api';
1011

1112
// Function to upsert check-in measurements
1213
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -34,11 +35,11 @@ const searchCustomCategory = async (name: string) => {
3435
}
3536
);
3637
return data;
37-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
38-
} catch (err: any) {
38+
} catch (err: unknown) {
39+
const message = getErrorMessage(err);
3940
// If it's a 404, it means no category is found, which is a valid scenario.
4041
// We return null in this case, and the calling function will handle it.
41-
if (err.message && err.message.includes('404')) {
42+
if (message && message.includes('404')) {
4243
return null;
4344
}
4445
console.error('Error searching custom category:', err);
@@ -131,8 +132,7 @@ export const processMeasurementInput = async (
131132
let upsertError = null;
132133
try {
133134
await upsertCheckInMeasurement(updateData);
134-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
135-
} catch (err: any) {
135+
} catch (err: unknown) {
136136
upsertError = err;
137137
}
138138

@@ -160,8 +160,7 @@ export const processMeasurementInput = async (
160160
let categorySearchError: any = null;
161161
try {
162162
existingCategory = await searchCustomCategory(customMeasurementName);
163-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
164-
} catch (err: any) {
163+
} catch (err: unknown) {
165164
categorySearchError = err;
166165
}
167166

@@ -198,8 +197,7 @@ export const processMeasurementInput = async (
198197
frequency: 'Daily',
199198
measurement_type: 'numeric',
200199
});
201-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
202-
} catch (err: any) {
200+
} catch (err: unknown) {
203201
categoryCreateError = err;
204202
}
205203

@@ -236,8 +234,7 @@ export const processMeasurementInput = async (
236234
value: valueToLog,
237235
entry_timestamp: new Date().toISOString(),
238236
});
239-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
240-
} catch (err: any) {
237+
} catch (err: unknown) {
241238
customEntryError = err;
242239
}
243240

SparkyFitnessFrontend/src/api/Chatbot/sparkyChatService.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { processWaterInput } from '@/api/Chatbot/Chatbot_WaterHandler';
1717
import { CoachResponse, FoodOption, Message } from '@/types/Chatbot_types';
1818
import { processChatInput } from '@/utils/Chatbot_utils';
1919
import { AIService } from '@/types/settings';
20+
import { getErrorMessage } from '@/utils/api';
2021

2122
export interface UserPreferences {
2223
auto_clear_history: 'never' | '7days' | 'all';
@@ -408,10 +409,10 @@ const getAIResponse = async (
408409
action: 'advice',
409410
response: response.content,
410411
};
411-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
412-
} catch (err: any) {
412+
} catch (err: unknown) {
413+
const message = getErrorMessage(err);
413414
error(userLoggingLevel, `[${transactionId}] Error in getAIResponse:`, err);
414-
if (err.message && err.message.includes('503')) {
415+
if (message && message.includes('503')) {
415416
return {
416417
action: 'none',
417418
response:
@@ -421,7 +422,7 @@ const getAIResponse = async (
421422
return {
422423
action: 'none',
423424
response:
424-
err.message ||
425+
message ||
425426
'An unexpected error occurred while trying to get an AI response.',
426427
};
427428
}
@@ -520,8 +521,7 @@ const callAIForFoodOptions = async (
520521
);
521522
return [];
522523
}
523-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
524-
} catch (err: any) {
524+
} catch (err: unknown) {
525525
error(userLoggingLevel, 'Error in callAIForFoodOptions:', err);
526526
return [];
527527
}

SparkyFitnessFrontend/src/api/CheckIn/moodService.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { api } from '@/api/api';
22
import type { MoodEntry } from '@/types/mood';
3+
import { getErrorMessage } from '@/utils/api';
34
import { debug, info, error } from '@/utils/logging';
45
import { getUserLoggingLevel } from '@/utils/userPreferences';
56

@@ -71,9 +72,9 @@ export const getMoodEntryByDate = async (
7172
});
7273
debug(userLoggingLevel, 'Response from getMoodEntryByDate API:', response);
7374
return response;
74-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
75-
} catch (err: any) {
76-
if (err.message && err.message.includes('404')) {
75+
} catch (err: unknown) {
76+
const message = getErrorMessage(err);
77+
if (message && message.includes('404')) {
7778
info(getUserLoggingLevel(), `No mood entry found for date ${entryDate}.`);
7879
return null;
7980
}

SparkyFitnessFrontend/src/api/Diary/dailyProgressService.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { GroupedExerciseEntry } from '@/types/exercises';
55
import { loadGoals } from '@/api/Goals/goals';
66
import { loadFoodEntries } from '@/api/Diary/foodEntryService';
77
import { loadExistingCheckInMeasurements } from '@/api/CheckIn/checkInService';
8+
import { getErrorMessage } from '@/utils/api';
89

910
export { getExerciseEntriesForDate } from '../Exercises/exerciseEntryService';
1011

@@ -25,9 +26,9 @@ export const getCheckInMeasurementsForDate = async (
2526
try {
2627
const measurement = await loadExistingCheckInMeasurements(date);
2728
return measurement || null;
28-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
29-
} catch (error: any) {
30-
if (error.message.includes('404')) {
29+
} catch (error: unknown) {
30+
const message = getErrorMessage(error);
31+
if (message.includes('404')) {
3132
return null;
3233
}
3334
throw error;

SparkyFitnessFrontend/src/api/Settings/aiServiceSettingsService.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { apiCall } from '@/api/api';
22
import { AIService, UserPreferencesChat } from '@/types/settings';
3+
import { getErrorMessage } from '@/utils/api';
34

45
export const getAIServices = async (): Promise<AIService[]> => {
56
try {
@@ -8,11 +9,11 @@ export const getAIServices = async (): Promise<AIService[]> => {
89
suppress404Toast: true, // Suppress toast for 404
910
});
1011
return services || []; // Return empty array if 404 (no services found)
11-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
12-
} catch (err: any) {
12+
} catch (err: unknown) {
13+
const message = getErrorMessage(err);
1314
// If it's a 404, it means no services are found, which is a valid scenario.
1415
// We return an empty array in this case, and the calling function will handle it.
15-
if (err.message && err.message.includes('404')) {
16+
if (message && message.includes('404')) {
1617
return [];
1718
}
1819
throw err;
@@ -26,11 +27,11 @@ export const getPreferences = async (): Promise<UserPreferencesChat> => {
2627
suppress404Toast: true, // Suppress toast for 404
2728
});
2829
return preferences;
29-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
30-
} catch (err: any) {
30+
} catch (err: unknown) {
31+
const message = getErrorMessage(err);
3132
// If it's a 404, it means no preferences are found, which is a valid scenario.
3233
// We return null in this case, and the calling function will handle it.
33-
if (err.message && err.message.includes('404')) {
34+
if (message && message.includes('404')) {
3435
return null;
3536
}
3637
throw err;
@@ -45,9 +46,9 @@ export const getActiveAiServiceSetting =
4546
suppress404Toast: true, // Suppress toast for 404
4647
});
4748
return setting;
48-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
49-
} catch (err: any) {
50-
if (err.message && err.message.includes('404')) {
49+
} catch (err: unknown) {
50+
const message = getErrorMessage(err);
51+
if (message && message.includes('404')) {
5152
return null;
5253
}
5354
throw err;
@@ -112,9 +113,9 @@ export const getGlobalAIServices = async (): Promise<AIService[]> => {
112113
suppress404Toast: true,
113114
});
114115
return services || [];
115-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
116-
} catch (err: any) {
117-
if (err.message && err.message.includes('404')) {
116+
} catch (err: unknown) {
117+
const message = getErrorMessage(err);
118+
if (message && message.includes('404')) {
118119
return [];
119120
}
120121
throw err;

SparkyFitnessFrontend/src/api/api.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,7 @@ export async function apiCall(
175175
);
176176
//console.log(`API Call: Returning JSON response for ${url}:`, jsonResponse); // Added console.log
177177
return jsonResponse;
178-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
179-
} catch (err: any) {
178+
} catch (err: unknown) {
180179
const errorMessage = err instanceof Error ? err.message : String(err);
181180
logging.error(userLoggingLevel, 'API call network error:', err); // Log the raw error object for better debugging
182181
toast({

SparkyFitnessFrontend/src/components/OidcCallback.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useEffect, useState, useRef } from 'react';
33
import { useNavigate } from 'react-router-dom';
44
import { authClient } from '../lib/auth-client';
55
import { useAuth } from '../hooks/useAuth';
6+
import { getErrorMessage } from '@/utils/api';
67

78
const OidcCallback: React.FC = () => {
89
const [error, setError] = useState<string | null>(null);
@@ -45,11 +46,10 @@ const OidcCallback: React.FC = () => {
4546
} else {
4647
setError('No active session found after OIDC redirect.');
4748
}
48-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
49-
} catch (err: any) {
49+
} catch (err: unknown) {
50+
const message = getErrorMessage(err);
5051
setError(
51-
err.message ||
52-
'An unexpected error occurred during OIDC verification.'
52+
message || 'An unexpected error occurred during OIDC verification.'
5353
);
5454
}
5555
};

SparkyFitnessFrontend/src/contexts/PreferencesContext.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
useCreateWaterContainerMutation,
2828
useSetPrimaryWaterContainerMutation,
2929
} from '@/hooks/Settings/useWaterContainers';
30+
import { getErrorMessage } from '@/utils/api';
3031

3132
// Function to fetch user preferences from the backend
3233

@@ -229,9 +230,9 @@ export const PreferencesProvider: React.FC<{ children: React.ReactNode }> = ({
229230
try {
230231
const data = await queryClient.fetchQuery(preferencesOptions.user());
231232
return data;
232-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
233-
} catch (err: any) {
234-
if (err.message && err.message.includes('404')) {
233+
} catch (err: unknown) {
234+
const message = getErrorMessage(err);
235+
if (message && message.includes('404')) {
235236
return null;
236237
}
237238
console.error('Error fetching user preferences:', err);
@@ -500,8 +501,7 @@ export const PreferencesProvider: React.FC<{ children: React.ReactNode }> = ({
500501
try {
501502
const data = await queryClient.fetchQuery(preferencesOptions.nutrients());
502503
setNutrientDisplayPreferences(data);
503-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
504-
} catch (err: any) {
504+
} catch (err: unknown) {
505505
console.error('Error fetching nutrient display preferences:', err);
506506
}
507507
}, [user, queryClient]);

0 commit comments

Comments
 (0)