🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
chore(ui): style TRPC error toast to differentiate between errors and warnings (#3095)
marliessophiec3c8a741e477
diff --git a/web/src/features/notifications/ErrorNotification.tsx b/web/src/features/notifications/ErrorNotification.tsxindex a3b35aeca4..14a0bff6d3 100644--- a/web/src/features/notifications/ErrorNotification.tsx+++ b/web/src/features/notifications/ErrorNotification.tsx@@ -8,6 +8,7 @@ import {interface ErrorNotificationProps {error: string;description: string;+ type: "WARNING" | "ERROR";cause?: string;dismissToast: (t?: string | number | undefined) => void;toast: string | number;@@ -17,11 +18,17 @@ interface ErrorNotificationProps {export const ErrorNotification: React.FC<ErrorNotificationProps> = ({error,description,+ type,cause,dismissToast,toast,path,}) => {+ const isError = type === "ERROR";+ const textColor = isError+ ? "text-destructive-foreground"+ : "text-dark-yellow";+const handleReportIssueClick = () => {if (chatAvailable) {const currentUrl = window.location.href;@@ -35,27 +42,29 @@ export const ErrorNotification: React.FC<ErrorNotificationProps> = ({<div className="flex justify-between"><div className="flex min-w-[300px] flex-1 flex-col gap-2"><div className="flex items-center gap-2">- <AlertTriangle size={20} className="text-destructive-foreground" />- <div className="m-0 text-sm font-medium leading-tight text-destructive-foreground">+ <AlertTriangle size={20} className={textColor} />+ <div className={`m-0 text-sm font-medium leading-tight ${textColor}`}>{error}</div></div>{description && (- <div className="text-sm leading-tight text-destructive-foreground">+ <div className={`text-sm leading-tight ${textColor}`}>{description}</div>)}{path && (- <div className="text-sm leading-tight text-destructive-foreground">+ <div className={`text-sm leading-tight ${textColor}`}>Path: {path}</div>)}{cause && (- <div className="max-h-32 overflow-y-auto text-sm leading-tight text-destructive-foreground">+ <div+ className={`max-h-32 overflow-y-auto text-sm leading-tight ${textColor}`}+ >{cause}</div>)}- {chatAvailable && (+ {isError && chatAvailable && (<Buttonvariant="errorNotification"size={"sm"}@@ -68,7 +77,7 @@ export const ErrorNotification: React.FC<ErrorNotificationProps> = ({)}</div><button- className="flex h-6 w-6 cursor-pointer items-start justify-end border-none bg-transparent p-0 text-destructive-foreground transition-colors duration-200"+ className={`flex h-6 w-6 cursor-pointer items-start justify-end border-none bg-transparent p-0 ${textColor} transition-colors duration-200`}onClick={() => dismissToast(toast)}aria-label="Close">diff --git a/web/src/features/notifications/showErrorToast.tsx b/web/src/features/notifications/showErrorToast.tsxindex 7c7ba23d1b..eeacf21bae 100644--- a/web/src/features/notifications/showErrorToast.tsx+++ b/web/src/features/notifications/showErrorToast.tsx@@ -1,9 +1,20 @@import { toast } from "sonner";import { ErrorNotification } from "@/src/features/notifications/ErrorNotification";+const toastErrorStyleProps = {+ border: "1px solid hsl(var(--destructive))",+ backgroundColor: "hsl(var(--destructive))",+};++const toastWarningStyleProps = {+ border: "1px solid hsl(var(--light-yellow))",+ backgroundColor: "hsl(var(--light-yellow))",+};+export const showErrorToast = (error: string,description: string,+ type: "WARNING" | "ERROR" = "ERROR",cause?: string,path?: string,) => {@@ -12,6 +23,7 @@ export const showErrorToast = (<ErrorNotificationerror={error}description={description}+ type={type}cause={cause}path={path}dismissToast={toast.dismiss}@@ -22,9 +34,8 @@ export const showErrorToast = (duration: Infinity,style: {padding: "1rem",- border: "1px solid hsl(var(--destructive))",borderRadius: "0.5rem",- backgroundColor: "hsl(var(--destructive))",+ ...(type === "ERROR" ? toastErrorStyleProps : toastWarningStyleProps),},},);diff --git a/web/src/utils/trpcErrorToast.tsx b/web/src/utils/trpcErrorToast.tsxindex 26a877c44a..5a663d49b6 100644--- a/web/src/utils/trpcErrorToast.tsx+++ b/web/src/utils/trpcErrorToast.tsx@@ -23,23 +23,44 @@ const errorTitleMap = {INTERNAL_SERVER_ERROR: "Internal Server Error",} as const;+const getErrorTitleAndHttpCode = (error: TRPCClientError<any>) => {+ const httpStatus: number =+ typeof error.data?.httpStatus === "number" ? error.data.httpStatus : 500;++ if (httpStatus in httpStatusOverride) {+ return {+ errorTitle: errorTitleMap[httpStatusOverride[httpStatus]],+ httpStatus,+ };+ }++ const errorTitle =+ error.data?.code in errorTitleMap+ ? errorTitleMap[error.data?.code as keyof typeof errorTitleMap]+ : "Unexpected Error";++ return { errorTitle, httpStatus };+};+export const trpcErrorToast = (error: unknown) => {if (error instanceof TRPCClientError) {const path = error.data?.path;const cause = error.data?.cause;const description = error.message;- const errorTitle =- error.data?.httpStatus in httpStatusOverride- ? errorTitleMap[httpStatusOverride[error.data?.httpStatus]]- : error.data?.code in errorTitleMap- ? errorTitleMap[error.data?.code as keyof typeof errorTitleMap]- : "Unexpected Error";-- showErrorToast(errorTitle, description, cause, path);++ const { errorTitle, httpStatus } = getErrorTitleAndHttpCode(error);+ showErrorToast(+ errorTitle,+ description,+ httpStatus >= 500 && httpStatus < 600 ? "ERROR" : "WARNING",+ cause,+ path,+ );} else {showErrorToast("Unexpected Error",- "An unexpected error occurred. Please try again.",+ "An unexpected error occurred.",+ "ERROR",);}};