change error connecting to backend when backend is cold started
This commit is contained in:
parent
d79366d8b2
commit
f22127124b
@ -17,6 +17,7 @@ from reflex.components.radix.themes.components.dialog import (
|
|||||||
from reflex.components.radix.themes.layout.flex import Flex
|
from reflex.components.radix.themes.layout.flex import Flex
|
||||||
from reflex.components.radix.themes.typography.text import Text
|
from reflex.components.radix.themes.typography.text import Text
|
||||||
from reflex.components.sonner.toast import Toaster, ToastProps
|
from reflex.components.sonner.toast import Toaster, ToastProps
|
||||||
|
from reflex.config import environment
|
||||||
from reflex.constants import Dirs, Hooks, Imports
|
from reflex.constants import Dirs, Hooks, Imports
|
||||||
from reflex.constants.compiler import CompileVars
|
from reflex.constants.compiler import CompileVars
|
||||||
from reflex.utils.imports import ImportVar
|
from reflex.utils.imports import ImportVar
|
||||||
@ -109,6 +110,17 @@ class ConnectionToaster(Toaster):
|
|||||||
id=toast_id,
|
id=toast_id,
|
||||||
) # pyright: ignore [reportCallIssue]
|
) # pyright: ignore [reportCallIssue]
|
||||||
|
|
||||||
|
if environment.DOES_BACKEND_COLD_START.get():
|
||||||
|
error_message = Var.create("Backend is starting.")
|
||||||
|
toast_var = Var(
|
||||||
|
f"toast.loading({error_message!s}, {{...toast_props, description: '', closeButton: false, onDismiss: () => setUserDismissed(true)}},)"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
error_message = Var.create(f"Cannot connect to server: {connection_error}.")
|
||||||
|
toast_var = Var(
|
||||||
|
f"toast.error({error_message!s}, {{...toast_props, onDismiss: () => setUserDismissed(true)}},)"
|
||||||
|
)
|
||||||
|
|
||||||
individual_hooks = [
|
individual_hooks = [
|
||||||
f"const toast_props = {LiteralVar.create(props)!s};",
|
f"const toast_props = {LiteralVar.create(props)!s};",
|
||||||
"const [userDismissed, setUserDismissed] = useState(false);",
|
"const [userDismissed, setUserDismissed] = useState(false);",
|
||||||
@ -127,10 +139,7 @@ class ConnectionToaster(Toaster):
|
|||||||
() => {{
|
() => {{
|
||||||
if ({has_too_many_connection_errors!s}) {{
|
if ({has_too_many_connection_errors!s}) {{
|
||||||
if (!userDismissed) {{
|
if (!userDismissed) {{
|
||||||
toast.error(
|
{toast_var!s}
|
||||||
`Cannot connect to server: ${{{connection_error}}}.`,
|
|
||||||
{{...toast_props, onDismiss: () => setUserDismissed(true)}},
|
|
||||||
)
|
|
||||||
}}
|
}}
|
||||||
}} else {{
|
}} else {{
|
||||||
toast.dismiss("{toast_id}");
|
toast.dismiss("{toast_id}");
|
||||||
|
@ -601,6 +601,9 @@ class EnvironmentVariables:
|
|||||||
# Paths to exclude from the hot reload. Takes precedence over include paths. Separated by a colon.
|
# Paths to exclude from the hot reload. Takes precedence over include paths. Separated by a colon.
|
||||||
REFLEX_HOT_RELOAD_EXCLUDE_PATHS: EnvVar[List[Path]] = env_var([])
|
REFLEX_HOT_RELOAD_EXCLUDE_PATHS: EnvVar[List[Path]] = env_var([])
|
||||||
|
|
||||||
|
# Enables different behavior for when the backend would do a cold start if it was inactive.
|
||||||
|
DOES_BACKEND_COLD_START: EnvVar[bool] = env_var(False)
|
||||||
|
|
||||||
|
|
||||||
environment = EnvironmentVariables()
|
environment = EnvironmentVariables()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user