diff --git a/backend/src/main/kotlin/no/bekk/database/ContextRepository.kt b/backend/src/main/kotlin/no/bekk/database/ContextRepository.kt index b8f21b759..32ec35227 100644 --- a/backend/src/main/kotlin/no/bekk/database/ContextRepository.kt +++ b/backend/src/main/kotlin/no/bekk/database/ContextRepository.kt @@ -1,5 +1,6 @@ package no.bekk.database +import io.ktor.server.plugins.* import no.bekk.configuration.Database import java.util.* import java.sql.SQLException @@ -104,7 +105,7 @@ object ContextRepository { name = result.getString("name") ) } else { - throw RuntimeException("Error getting context") + throw NotFoundException("Context with id $id not found") } } } diff --git a/backend/src/main/kotlin/no/bekk/routes/ContextRouting.kt b/backend/src/main/kotlin/no/bekk/routes/ContextRouting.kt index db0764a86..a73294416 100644 --- a/backend/src/main/kotlin/no/bekk/routes/ContextRouting.kt +++ b/backend/src/main/kotlin/no/bekk/routes/ContextRouting.kt @@ -82,7 +82,7 @@ fun Route.contextRouting() { val contextId = call.parameters["contextId"] ?: throw BadRequestException("Missing contextId") if (!hasContextAccess(call, contextId)) { - call.respond(HttpStatusCode.Forbidden) + call.respond(HttpStatusCode.Unauthorized) return@get } val context = ContextRepository.getContext(contextId) diff --git a/frontend/beCompliant/src/hooks/useFetchContext.ts b/frontend/beCompliant/src/hooks/useFetchContext.ts index 10e6b8daa..8f24d5b52 100644 --- a/frontend/beCompliant/src/hooks/useFetchContext.ts +++ b/frontend/beCompliant/src/hooks/useFetchContext.ts @@ -2,9 +2,10 @@ import { useQuery } from '@tanstack/react-query'; import { apiConfig } from '../api/apiConfig'; import { axiosFetch } from '../api/Fetch'; import { Context } from './useFetchTeamContexts'; +import { AxiosError } from 'axios'; export function useFetchContext(contextId?: string) { - return useQuery({ + return useQuery({ queryKey: apiConfig.contexts.byId.queryKey(contextId!), queryFn: () => axiosFetch({ diff --git a/frontend/beCompliant/src/pages/ActivityPage.tsx b/frontend/beCompliant/src/pages/ActivityPage.tsx index 4087488bb..2dbb54ff9 100644 --- a/frontend/beCompliant/src/pages/ActivityPage.tsx +++ b/frontend/beCompliant/src/pages/ActivityPage.tsx @@ -135,7 +135,18 @@ export const ActivityPage = () => { type: OptionalFieldType.OPTION_SINGLE, }; - if (error) { + if (contextError) { + const statusCode = contextError.response?.status; + if (statusCode === 401) { + return ( + + ); + } else if (statusCode === 404) { + return ( + + ); + } + } else if (error) { return ; }