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,
|
||||
removeExtraHeader,
|
||||
getVisitorId,
|
||||
ApiError,
|
||||
} from "@workspace/api-client-react";
|
||||
import { ConsentDialog } from "@/components/consent-dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
@@ -154,8 +155,14 @@ export default function Home() {
|
||||
queryClient.invalidateQueries({ queryKey: getListIdeasQueryKey() });
|
||||
queryClient.invalidateQueries({ queryKey: getGetIdeaStatsQueryKey() });
|
||||
},
|
||||
onError: () => {
|
||||
setSubmitResult({ success: false, message: "Une erreur est survenue lors de l'envoi. Veuillez réessayer." });
|
||||
onError: (error) => {
|
||||
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: () => {
|
||||
removeExtraHeader("x-hcaptcha-token");
|
||||
@@ -411,7 +418,11 @@ export default function Home() {
|
||||
: <Info className="h-4 w-4 text-amber-600" />
|
||||
}
|
||||
<AlertTitle>
|
||||
{submitResult.success ? "Contribution enregistrée" : "Contribution non retenue"}
|
||||
{submitResult.success
|
||||
? "Contribution enregistrée"
|
||||
: submitResult.reason
|
||||
? "Contribution non retenue"
|
||||
: "Envoi impossible"}
|
||||
</AlertTitle>
|
||||
<AlertDescription>
|
||||
{submitResult.message}
|
||||
|
||||
@@ -7,5 +7,6 @@ export {
|
||||
getVisitorId,
|
||||
addExtraHeader,
|
||||
removeExtraHeader,
|
||||
ApiError,
|
||||
} from "./custom-fetch";
|
||||
export type { AuthTokenGetter } from "./custom-fetch";
|
||||
|
||||
Reference in New Issue
Block a user