Show API error message to user instead of generic fallback
- Export ApiError from api-client-react package - home.tsx onError: extract error.data.message from ApiError and display it (cooldown, rate limit, consent_required, validation messages are now visible) - Differentiate alert title: "Contribution non retenue" for AI rejection (has a reason), "Envoi impossible" for technical errors Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -18,6 +18,7 @@ import {
|
|||||||
addExtraHeader,
|
addExtraHeader,
|
||||||
removeExtraHeader,
|
removeExtraHeader,
|
||||||
getVisitorId,
|
getVisitorId,
|
||||||
|
ApiError,
|
||||||
} from "@workspace/api-client-react";
|
} from "@workspace/api-client-react";
|
||||||
import { ConsentDialog } from "@/components/consent-dialog";
|
import { ConsentDialog } from "@/components/consent-dialog";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
@@ -154,8 +155,14 @@ export default function Home() {
|
|||||||
queryClient.invalidateQueries({ queryKey: getListIdeasQueryKey() });
|
queryClient.invalidateQueries({ queryKey: getListIdeasQueryKey() });
|
||||||
queryClient.invalidateQueries({ queryKey: getGetIdeaStatsQueryKey() });
|
queryClient.invalidateQueries({ queryKey: getGetIdeaStatsQueryKey() });
|
||||||
},
|
},
|
||||||
onError: () => {
|
onError: (error) => {
|
||||||
setSubmitResult({ success: false, message: "Une erreur est survenue lors de l'envoi. Veuillez réessayer." });
|
const apiMessage = error instanceof ApiError
|
||||||
|
? (error.data as { message?: string } | null)?.message
|
||||||
|
: undefined;
|
||||||
|
setSubmitResult({
|
||||||
|
success: false,
|
||||||
|
message: apiMessage ?? "Une erreur est survenue lors de l'envoi. Veuillez réessayer.",
|
||||||
|
});
|
||||||
},
|
},
|
||||||
onSettled: () => {
|
onSettled: () => {
|
||||||
removeExtraHeader("x-hcaptcha-token");
|
removeExtraHeader("x-hcaptcha-token");
|
||||||
@@ -411,7 +418,11 @@ export default function Home() {
|
|||||||
: <Info className="h-4 w-4 text-amber-600" />
|
: <Info className="h-4 w-4 text-amber-600" />
|
||||||
}
|
}
|
||||||
<AlertTitle>
|
<AlertTitle>
|
||||||
{submitResult.success ? "Contribution enregistrée" : "Contribution non retenue"}
|
{submitResult.success
|
||||||
|
? "Contribution enregistrée"
|
||||||
|
: submitResult.reason
|
||||||
|
? "Contribution non retenue"
|
||||||
|
: "Envoi impossible"}
|
||||||
</AlertTitle>
|
</AlertTitle>
|
||||||
<AlertDescription>
|
<AlertDescription>
|
||||||
{submitResult.message}
|
{submitResult.message}
|
||||||
|
|||||||
@@ -7,5 +7,6 @@ export {
|
|||||||
getVisitorId,
|
getVisitorId,
|
||||||
addExtraHeader,
|
addExtraHeader,
|
||||||
removeExtraHeader,
|
removeExtraHeader,
|
||||||
|
ApiError,
|
||||||
} from "./custom-fetch";
|
} from "./custom-fetch";
|
||||||
export type { AuthTokenGetter } from "./custom-fetch";
|
export type { AuthTokenGetter } from "./custom-fetch";
|
||||||
|
|||||||
Reference in New Issue
Block a user