Skip to content

Commit 2d14f28

Browse files
Add connection_error_message to configuration for custom connection error toaster in prod mode
1 parent 1e71398 commit 2d14f28

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

reflex/components/core/banner.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from reflex.components.radix.themes.layout.flex import Flex
1717
from reflex.components.radix.themes.typography.text import Text
1818
from reflex.components.sonner.toast import ToastProps, toast_ref
19+
from reflex.config import get_config
1920
from reflex.constants import Dirs, Hooks, Imports
2021
from reflex.constants.compiler import CompileVars
2122
from reflex.environment import environment
@@ -100,9 +101,13 @@ def add_hooks(self) -> list[str | Var]:
100101
"""
101102
toast_id = "websocket-error"
102103
target_url = WebsocketTargetURL.create()
104+
config = get_config()
103105
props = ToastProps(
104106
description=LiteralVar.create(
105-
f"Check if server is reachable at {target_url}",
107+
f"Check if server is reachable at {target_url}"
108+
if environment.REFLEX_ENV_MODE.get().value == constants.Env.DEV
109+
or not config.connection_error_message
110+
else config.connection_error_message
106111
),
107112
close_button=True,
108113
duration=120000,
@@ -135,6 +140,9 @@ def add_hooks(self) -> list[str | Var]:
135140
else:
136141
loading_message = Var.create(
137142
f"Cannot connect to server: {connection_error}."
143+
if environment.REFLEX_ENV_MODE.get().value == constants.Env.DEV
144+
or not config.connection_error_message
145+
else ""
138146
)
139147
toast_var = Var(
140148
f"toast?.error({loading_message!s}, {{...toast_props, onDismiss: () => setUserDismissed(true)}},)"

reflex/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ class BaseConfig:
262262

263263
_prefixes: ClassVar[list[str]] = ["REFLEX_"]
264264

265+
connection_error_message: str | None = None
266+
265267

266268
_PLUGINS_ENABLED_BY_DEFAULT = [
267269
SitemapPlugin,

0 commit comments

Comments
 (0)