Skip to content

Commit

Permalink
feat: show better error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ledouxm committed May 23, 2024
1 parent 8470ca6 commit 250ac7c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/backend/src/services/userService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ const assertEmailDoesNotAlreadyExist = async (email: string) => {
};

const assertEmailInWhitelist = async (email: string) => {
if (isDev) return;
// if (isDev) return;
const whitelist = await db.whitelist.findFirst({ where: { email } });

if (!whitelist) {
Expand Down
4 changes: 4 additions & 0 deletions packages/frontend/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ export type RouterInputs<T extends keyof AllEndpoints> = AllEndpoints[T]["parame
export type RouterOutputs<T extends keyof AllEndpoints> = AllEndpoints[T]["response"];

type AllEndpoints = GetEndpoints & PostEndpoints;

export const getErrorMessage = (error: any) => {
return error?.data?.error ?? "Une erreur est survenue, veuillez réessayer plus tard";
};
4 changes: 2 additions & 2 deletions packages/frontend/src/components/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { FullWidthButton } from "./FullWidthButton";
import { InputGroup } from "./InputGroup";
import { PasswordInput } from "./PasswordInput";
import { useMutation } from "@tanstack/react-query";
import { type RouterInputs, api } from "../api";
import { type RouterInputs, api, getErrorMessage } from "../api";

export const LoginForm = () => {
const [authData, setAuthData] = useAuthContext();
Expand All @@ -32,7 +32,7 @@ export const LoginForm = () => {
<Alert
className={css({ mb: "1.5rem" })}
severity="error"
title={<styled.span fontWeight="regular">{(mutationError as any).message}</styled.span>}
title={<styled.span fontWeight="regular">{getErrorMessage(mutationError)}</styled.span>}
/>
) : null}
<InputGroup state={mutationError ? "error" : undefined}>
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/components/SignupForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { InputGroup } from "./InputGroup";
import Alert from "@codegouvfr/react-dsfr/Alert";
import { useAuthContext } from "../contexts/AuthContext";
import { useMutation, useQuery } from "@tanstack/react-query";
import { type RouterInputs, api } from "../api";
import { type RouterInputs, api, getErrorMessage } from "../api";
import Select from "@codegouvfr/react-dsfr/Select";

export const SignupForm = () => {
Expand Down Expand Up @@ -49,7 +49,7 @@ export const SignupForm = () => {
<Alert
className={css({ mb: "1.5rem" })}
severity="error"
title={<styled.span fontWeight="regular">{(mutationError as any).message}</styled.span>}
title={<styled.span fontWeight="regular">{getErrorMessage(mutationError)}</styled.span>}
/>
) : null}
<InputGroup state={mutationError ? "error" : undefined}>
Expand Down

0 comments on commit 250ac7c

Please sign in to comment.