fix: response error toast style

Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
Innei 2024-11-01 15:48:40 +08:00
parent e205f393fb
commit 7748588608
No known key found for this signature in database
GPG Key ID: 0F62D33977F021F7
2 changed files with 21 additions and 3 deletions

View File

@ -7,6 +7,8 @@ import { toast } from "sonner"
import { CopyButton } from "~/components/ui/code-highlighter"
import { Markdown } from "~/components/ui/markdown/Markdown"
import { isDev } from "~/constants"
import { DebugRegistry } from "~/modules/debug/registry"
export const getFetchErrorMessage = (error: Error) => {
if (error instanceof FetchError) {
@ -62,7 +64,7 @@ export const toastFetchError = (
..._toastOptions,
classNames: {
toast: "items-start bg-theme-background",
title: tw`-mt-0.5`, // to align with the icon (actually cut the top space from line-height)
content: "w-full",
..._toastOptions.classNames,
},
@ -95,3 +97,19 @@ export const toastFetchError = (
})
}
}
if (isDev) {
DebugRegistry.add("Simulate request error", () => {
createErrorToaster(
"Simulated request error",
{},
)({
response: {
_data: JSON.stringify({
code: 1000,
message: "Simulated request error",
reason: "Simulated reason",
}),
},
} as any)
})
}

View File

@ -35,8 +35,8 @@ export const EnvironmentIndicator = () => {
<div className="flex flex-col gap-2">
{Object.entries(actionMap).map(([key, action]) => {
return (
<div key={key} className="flex items-center gap-2">
<span>{key}</span>
<div key={key} className="flex w-full items-center gap-2">
<span className="flex flex-1">{key}</span>
<Button variant="outline" type="button" onClick={() => action()}>
<i className="i-mgc-play-cute-fi size-3" />
<span className="ml-1">Run</span>