diff --git a/frontend/src/services/search/openings.ts b/frontend/src/services/search/openings.ts index 0e87a155..84a24fbb 100644 --- a/frontend/src/services/search/openings.ts +++ b/frontend/src/services/search/openings.ts @@ -121,8 +121,6 @@ export const fetchOpenings = async (filters: OpeningFilters): Promise => { // Used to fetch the recent openings for a user based on a limit value export const fetchUserRecentOpenings = async (limit: number): Promise => { - - // Retrieve the auth token const authToken = getAuthIdToken(); // Make the API request with the Authorization header @@ -132,6 +130,14 @@ export const fetchUserRecentOpenings = async (limit: number): Promise => { } }); + // Handle empty or invalid data gracefully + if (!response.data || response.data.data === null || response.data.data.length === 0) { + return { + ...response.data, + data: [] // Return empty array for `data` to signal no results + }; + } + // Flatten the data part of the response const flattenedData = response.data.data.map((item: OpeningItem) => ({ ...item, @@ -143,13 +149,14 @@ export const fetchUserRecentOpenings = async (limit: number): Promise => { category: undefined // Remove the old nested category object })); - // Returning the modified response data with the flattened structure + // Return the modified response data with the flattened structure return { ...response.data, data: flattenedData }; }; + export const fetchCategories = async (): Promise => { // Retrieve the auth token const authToken = getAuthIdToken();