diff --git a/src/lib/services/dictionary.ts b/src/lib/services/dictionary.ts index 3a64c91f..3f4f0794 100644 --- a/src/lib/services/dictionary.ts +++ b/src/lib/services/dictionary.ts @@ -49,16 +49,6 @@ export function searchDictionary( ); } -export async function getAllFacets(): Promise { - let request: DictionarySearchRequest = { facets: [], search: '' }; - if (!get(page).url.pathname.includes('/discover')) { - request = addConsents(request); - } - const response: DictionaryFacetResult[] = await api.post(`${dictionaryUrl}facets/`, request); - initializeHiddenFacets(response); - return response; -} - function initializeHiddenFacets(response: DictionaryFacetResult[]) { // facets that have a count of zero should never be shown in the UI // this happens because of consent filters @@ -87,11 +77,17 @@ export async function updateFacetsFromSearch( request = addConsents(request); } - const response: DictionaryFacetResult[] = await api.post(`${dictionaryUrl}facets/`, request); - if (facets.length === 0 && search.length === 0) { - initializeHiddenFacets(response); + try { + const response: DictionaryFacetResult[] = await api.post(`${dictionaryUrl}facets/`, request); + if (facets.length === 0 && search.length === 0) { + initializeHiddenFacets(response); + } + return response; + } catch (error) { + console.error('Failed to update facets from search:', error); + // You might want to throw the error or return a default value depending on your use case + return []; } - return response; } export async function getConceptDetails( diff --git a/src/lib/stores/User.ts b/src/lib/stores/User.ts index 2d8a88b4..6e7e0dcf 100644 --- a/src/lib/stores/User.ts +++ b/src/lib/stores/User.ts @@ -138,8 +138,12 @@ export async function login(token: string) { export async function logout(authProvider?: AuthProvider, redirect = false) { if (browser) { const token = localStorage.getItem('token'); - token && api.get('/psama/logout'); - token && localStorage.removeItem('token'); + if (token) { + api.get('/psama/logout').catch((error) => { + console.error('Error logging out: ' + error); + }); + localStorage.removeItem('token'); + } } // get the auth provider