Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

💄 Show participant friendly error messages on failed submissions (#2850)

Luke Vella8cf9185e6a2a
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.json
index cc21f4230..69c3328ab 100644
--- a/apps/web/public/locales/en/app.json
+++ b/apps/web/public/locales/en/app.json
@@ -15,6 +15,7 @@
"actionErrorForbidden": "You are not allowed to perform this action",
"actionErrorInternalServerError": "An internal server error occurred",
"actionErrorInvalidSession": "Your session is no longer valid",
+ "actionErrorNetwork": "Unable to reach the server. Please check your connection and try again.",
"actionErrorNotFound": "The resource was not found",
"actionErrorPayloadTooLarge": "The file you uploaded is too large. Please try a smaller file.",
"actionErrorPaymentRequired": "You need to upgrade to perform this action",
@@ -462,6 +463,9 @@
"newParticipantDialogSuccessTitle": "Your response has been saved",
"newParticipantFormAddNote": "Add a note",
"newParticipantFormDescription": "Fill in the form below to submit your votes.",
+ "newParticipantFormErrorPollFull": "This poll is no longer accepting responses.",
+ "newParticipantFormErrorTooManyRequests": "You have made too many attempts. Please wait a while and try again.",
+ "newParticipantFormErrorUnauthorized": "We couldn't verify your session. Please refresh the page and try again.",
"newParticipantFormNoteDescription": "Only the organizer will see this note.",
"newParticipantFormNoteLabel": "Note for the organizer",
"newParticipantFormSubmit": "Save availability",
diff --git a/apps/web/src/features/poll/components/new-participant-modal.tsx b/apps/web/src/features/poll/components/new-participant-modal.tsx
index 3edd923c4..7f20222c6 100644
--- a/apps/web/src/features/poll/components/new-participant-modal.tsx
+++ b/apps/web/src/features/poll/components/new-participant-modal.tsx
@@ -145,6 +145,32 @@ export const NewParticipantForm = (props: NewParticipantModalProps) => {
});
const { setError, formState, handleSubmit, watch } = form;
+
+ const getSubmitErrorMessage = (error: unknown) => {
+ if (error instanceof TRPCClientError && error.data) {
+ if (error.data.appError === "POLL_FULL") {
+ return t("newParticipantFormErrorPollFull", {
+ defaultValue: "This poll is no longer accepting responses.",
+ });
+ }
+ switch (error.data.code) {
+ case "TOO_MANY_REQUESTS":
+ return t("newParticipantFormErrorTooManyRequests", {
+ defaultValue:
+ "You have made too many attempts. Please wait a while and try again.",
+ });
+ case "UNAUTHORIZED":
+ return t("newParticipantFormErrorUnauthorized", {
+ defaultValue:
+ "We couldn't verify your session. Please refresh the page and try again.",
+ });
+ }
+ }
+ return t("newParticipantFormSubmitError", {
+ defaultValue:
+ "Your response could not be saved. Please check your connection and try again.",
+ });
+ };
const noteLength = watch("note")?.length ?? 0;
const [showNote, setShowNote] = React.useState(false);
const addParticipant = useAddParticipantMutation();
@@ -244,15 +270,7 @@ export const NewParticipantForm = (props: NewParticipantModalProps) => {
});
props.onSubmit?.(newParticipant);
} catch (error) {
- setError("root", {
- message:
- error instanceof TRPCClientError
- ? error.message
- : t("newParticipantFormSubmitError", {
- defaultValue:
- "Your response could not be saved. Please check your connection and try again.",
- }),
- });
+ setError("root", { message: getSubmitErrorMessage(error) });
}
})}
className="space-y-4"
diff --git a/apps/web/src/lib/errors/app-error.ts b/apps/web/src/lib/errors/app-error.ts
index c6193e088..f4c59c7fd 100644
--- a/apps/web/src/lib/errors/app-error.ts
+++ b/apps/web/src/lib/errors/app-error.ts
@@ -6,6 +6,7 @@ export type AppErrorCode =
| "INTERNAL_SERVER_ERROR"
| "PAYMENT_REQUIRED"
| "PAYLOAD_TOO_LARGE"
+ | "POLL_FULL"
| "SERVICE_UNAVAILABLE"
| "SETUP_REQUIRED"
| "TOO_MANY_REQUESTS";
diff --git a/apps/web/src/trpc/client/provider.tsx b/apps/web/src/trpc/client/provider.tsx
index 575c8e0ba..3aaa0cae4 100644
--- a/apps/web/src/trpc/client/provider.tsx
+++ b/apps/web/src/trpc/client/provider.tsx
@@ -27,6 +27,20 @@ export function TRPCProvider(props: { children: React.ReactNode }) {
return;
}
+ // Missing error data means no usable server response: the request
+ // failed in transit or the response was not a tRPC error envelope
+ // (e.g. an HTML error page from a proxy)
+ if (!error.data) {
+ toast.error(
+ t("actionErrorNetwork", {
+ defaultValue:
+ "Unable to reach the server. Please check your connection and try again.",
+ }),
+ { id: "network-error" },
+ );
+ return;
+ }
+
switch (error.data?.code) {
case "UNAUTHORIZED":
// Never sign out automatically — a failed sign out turns this
diff --git a/apps/web/src/trpc/routers/polls/participants.ts b/apps/web/src/trpc/routers/polls/participants.ts
index 9522d3d68..d72205b85 100644
--- a/apps/web/src/trpc/routers/polls/participants.ts
+++ b/apps/web/src/trpc/routers/polls/participants.ts
@@ -10,6 +10,7 @@ import * as z from "zod";
import { getInstanceBranding, getSpaceBranding } from "@/emails/branding";
import { getNotificationRecipient } from "@/features/notifications/data";
import { hasPollAdminAccess } from "@/features/poll/data";
+import { AppError } from "@/lib/errors/app-error";
import { track } from "@/lib/posthog";
import {
createRateLimitMiddleware,
@@ -278,6 +279,10 @@ export const participants = router({
throw new TRPCError({
code: "BAD_REQUEST",
message: `This poll has reached its maximum limit of ${MAX_PARTICIPANTS} participants`,
+ cause: new AppError({
+ code: "POLL_FULL",
+ message: "Poll has reached the maximum number of participants",
+ }),
});
}