Merge pull request #5374 from continuedev/nate/err-dialog

better error dialog for models add-on limit
This commit is contained in:
Dallin Romney 2025-04-28 16:17:47 -07:00 • committed by GitHub
commit d43663fcb0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 81 additions and 19 deletions

View file

@ -6,7 +6,6 @@ import {
CloseButton,
VSC_BACKGROUND_VAR,
defaultBorderRadius,
lightGray,
parseColorForHex,
vscBackground,
vscForeground,
@ -38,7 +37,7 @@ const DialogContainer = styled.div`
border-radius: ${defaultBorderRadius};
display: flex;
flex-direction: column;
border: 1px solid ${lightGray};
box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
word-wrap: break-word;
`;

View file

@ -0,0 +1,44 @@
import { DISCORD_LINK, GITHUB_LINK } from "core/util/constants";
import { useContext } from "react";
import { SecondaryButton } from "../../components";
import { DiscordIcon } from "../../components/svg/DiscordIcon";
import { GithubIcon } from "../../components/svg/GithubIcon";
import { IdeMessengerContext } from "../../context/IdeMessenger";
export function ModelsAddOnLimitDialog() {
const ideMessenger = useContext(IdeMessengerContext);
return (
<div className={`flex flex-col gap-1 px-3 pb-2 pt-3`}>
<p className="m-0 p-0 text-lg">Models Add-On Limit Reached</p>
<div className="mt-2 flex flex-col gap-1.5">
<span>
You have reached the monthly limit for chat requests with the Models
Add-On. This limit exists to avoid abuse, but if this happened from
normal usage we encourage you to contact us on GitHub or Discord
</span>
<div className="flex flex-row flex-wrap items-center gap-2">
<SecondaryButton
className="flex flex-row items-center gap-2 hover:opacity-70"
onClick={() => {
ideMessenger.post("openUrl", GITHUB_LINK);
}}
>
<GithubIcon className="h-5 w-5" />
<span className="xs:flex hidden">Github</span>
</SecondaryButton>
<SecondaryButton
className="flex flex-row items-center gap-2 hover:opacity-70"
onClick={() => {
ideMessenger.post("openUrl", DISCORD_LINK);
}}
>
<DiscordIcon className="h-5 w-5" />
<span className="xs:flex hidden">Discord</span>
</SecondaryButton>
</div>
</div>
</div>
);
}

View file

@ -1,6 +1,9 @@
import { Cog8ToothIcon } from "@heroicons/react/24/outline";
import {
ArrowTopRightOnSquareIcon,
Cog8ToothIcon,
} from "@heroicons/react/24/outline";
import { DISCORD_LINK, GITHUB_LINK } from "core/util/constants";
import { useContext } from "react";
import { useContext, useMemo } from "react";
import { Button, SecondaryButton } from "../../components";
import { DiscordIcon } from "../../components/svg/DiscordIcon";
import { GithubIcon } from "../../components/svg/GithubIcon";
@ -13,10 +16,22 @@ import { selectSelectedChatModel } from "../../redux/slices/configSlice";
import { setDialogMessage, setShowDialog } from "../../redux/slices/uiSlice";
import { isLocalProfile } from "../../util";
import { providers } from "../AddNewModel/configs/providers";
import { ModelsAddOnLimitDialog } from "./ModelsAddOnLimitDialog";
interface StreamErrorProps {
error: unknown;
}
function parseErrorMessage(fullErrMsg: string): string {
const msg = fullErrMsg.split("\n\n").slice(1).join("\n\n");
try {
const parsed = JSON.parse(msg);
return parsed.error ?? parsed.message ?? msg;
} catch (e) {
return msg;
}
}
const StreamErrorDialog = ({ error }: StreamErrorProps) => {
const dispatch = useAppDispatch();
const ideMessenger = useContext(IdeMessengerContext);
@ -25,6 +40,11 @@ const StreamErrorDialog = ({ error }: StreamErrorProps) => {
const selectedProfile = useAppSelector(selectSelectedProfile);
const { session, refreshProfiles } = useAuth();
const parsedError = useMemo<string>(
() => parseErrorMessage((error as any)?.message || ""),
[error],
);
const handleRefreshProfiles = () => {
refreshProfiles();
dispatch(setShowDialog(false));
@ -103,6 +123,12 @@ const StreamErrorDialog = ({ error }: StreamErrorProps) => {
</SecondaryButton>
);
if (
parsedError === "You have exceeded the chat limit for the Models Add-On."
) {
return <ModelsAddOnLimitDialog />;
}
let errorContent: React.ReactNode = <></>;
// Display components for specific errors
@ -206,19 +232,22 @@ const StreamErrorDialog = ({ error }: StreamErrorProps) => {
}
return (
<div className={`flex flex-col gap-1 px-3 pb-2 pt-2`}>
<p className="m-0 p-0 text-lg text-red-500">{`${statusCode ? statusCode + " " : ""}Error`}</p>
<div className={`flex flex-col gap-1 px-3 pb-2 pt-3`}>
<p className="m-0 p-0 text-lg text-red-500">{`Error (status code ${statusCode})`}</p>
{message ? (
<div className="mt-2 flex flex-col gap-0 rounded-sm border border-solid">
<code className="max-h-20 overflow-y-auto px-1 py-1">{message}</code>
<div className="mt-2 flex flex-col gap-0 rounded-sm">
<code className="max-h-20 overflow-y-auto p-2 font-mono">
{parsedError}
</code>
<div
className="flex cursor-pointer flex-row justify-end px-1 py-1 hover:underline"
className="flex cursor-pointer flex-row items-center justify-end px-1 py-1 text-gray-500 hover:underline"
onClick={() => {
ideMessenger.post("toggleDevTools", undefined);
}}
>
<span className="px-2">View Logs</span>
<ArrowTopRightOnSquareIcon className="h-4 w-4" />
</div>
</div>
) : null}
@ -246,16 +275,6 @@ const StreamErrorDialog = ({ error }: StreamErrorProps) => {
<span className="xs:flex hidden">Discord</span>
</SecondaryButton>
</div>
<div className="flex flex-row justify-end">
<Button
onClick={() => {
dispatch(setDialogMessage(undefined));
dispatch(setShowDialog(false));
}}
>
Close
</Button>
</div>
</div>
</div>
);