fix: error message (update title) (#2691)

This commit is contained in:
Catalin Pit
2026-04-22 08:42:07 +03:00
committed by GitHub
parent 3249f855fb
commit d38d703fd3
2 changed files with 30 additions and 13 deletions
@@ -8,6 +8,7 @@ import { DocumentDistributionMethod, DocumentSigningOrder } from '@prisma/client
import { FileTextIcon, InfoIcon, Plus, UploadCloudIcon, X } from 'lucide-react';
import { useFieldArray, useForm } from 'react-hook-form';
import { useNavigate } from 'react-router';
import { match } from 'ts-pattern';
import * as z from 'zod';
import { APP_DOCUMENT_UPLOAD_SIZE_LIMIT } from '@documenso/lib/constants/app';
@@ -19,7 +20,7 @@ import {
DO_NOT_INVALIDATE_QUERY_ON_MUTATION,
SKIP_QUERY_BATCH_META,
} from '@documenso/lib/constants/trpc';
import { AppError } from '@documenso/lib/errors/app-error';
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
import { type TRecipientLite, ZRecipientEmailSchema } from '@documenso/lib/types/recipient';
import { putPdfFile } from '@documenso/lib/universal/upload/put-file';
import { trpc } from '@documenso/trpc/react';
@@ -47,7 +48,6 @@ import {
import { Input } from '@documenso/ui/primitives/input';
import { SpinnerBox } from '@documenso/ui/primitives/spinner';
import { Tooltip, TooltipContent, TooltipTrigger } from '@documenso/ui/primitives/tooltip';
import type { Toast } from '@documenso/ui/primitives/use-toast';
import { useToast } from '@documenso/ui/primitives/use-toast';
const ZAddRecipientsForNewDocumentSchema = z.object({
@@ -201,19 +201,32 @@ export function TemplateUseDialog({
} catch (err) {
const error = AppError.parseError(err);
const toastPayload: Toast = {
const errorMessage = match(error.code)
.with(
'DOCUMENT_SEND_FAILED',
() => msg`The document was created but could not be sent to recipients.`,
)
.with(
AppErrorCode.INVALID_BODY,
AppErrorCode.INVALID_REQUEST,
() =>
msg`The document could not be created because of missing or invalid information. Please review the template's recipients and fields.`,
)
.with(
AppErrorCode.NOT_FOUND,
() => msg`The template or one of its recipients could not be found.`,
)
.with(
AppErrorCode.LIMIT_EXCEEDED,
() => msg`You have reached your document limit for this plan.`,
)
.otherwise(() => msg`An error occurred while creating document from template.`);
toast({
title: _(msg`Error`),
description: _(msg`An error occurred while creating document from template.`),
description: _(errorMessage),
variant: 'destructive',
};
if (error.code === 'DOCUMENT_SEND_FAILED') {
toastPayload.description = _(
msg`The document was created but could not be sent to recipients.`,
);
}
toast(toastPayload);
});
}
};