Skip to content

Commit

Permalink
fix: unfriendly error message when authentication fails on the client…
Browse files Browse the repository at this point in the history
… side

closes #5079
  • Loading branch information
Miodec committed Feb 22, 2024
1 parent bebd11a commit 34161dd
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions frontend/src/ts/ape/adapters/axios-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -44,11 +45,34 @@ function apeifyClientMethod(
): Ape.EndpointResponse<TData> {
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)(
Expand Down

0 comments on commit 34161dd

Please sign in to comment.