diff --git a/frontend/src/ts/ape/adapters/axios-adapter.ts b/frontend/src/ts/ape/adapters/axios-adapter.ts index 241991123f6e..fa6666b0591f 100644 --- a/frontend/src/ts/ape/adapters/axios-adapter.ts +++ b/frontend/src/ts/ape/adapters/axios-adapter.ts @@ -2,6 +2,7 @@ import { getAuthenticatedUser, isAuthenticated } from "../../firebase"; import { getIdToken } from "firebase/auth"; import axios, { AxiosRequestConfig, AxiosResponse } from "axios"; import { envConfig } from "../../constants/env-config"; +import { createErrorMessage } from "../../utils/misc"; type AxiosClientMethod = ( endpoint: string, @@ -44,11 +45,34 @@ function apeifyClientMethod( ): Ape.EndpointResponse { let errorMessage = ""; + let requestOptions: AxiosRequestConfig; try { - const requestOptions: AxiosRequestConfig = await adaptRequestOptions( - options + requestOptions = await adaptRequestOptions(options); + } catch (error) { + console.error("Failed to adapt request options"); + console.error(error); + + if ((error as Error).message.includes("auth/network-request-failed")) { + return { + status: 400, + message: + "Network error while trying to authenticate. Please try again.", + data: null, + }; + } + + const message = createErrorMessage( + error, + "Failed to adapt request options" ); + return { + status: 400, + message: message, + data: null, + }; + } + try { let response; if (methodType === "get" || methodType === "delete") { response = await (clientMethod as AxiosClientMethod)(