reflex icon indicating copy to clipboard operation
reflex copied to clipboard

Allow custom toast message for socket disconnection errors

Open lcastiglione opened this issue 10 months ago • 6 comments

Describe the Enhancement you want A clear and concise description of what the improvement does.

The enhancement allows customizing the message displayed in the toast notification when a socket disconnection error occurs. Currently, the error message is hardcoded or generic, which limits the ability to provide more user-friendly or context-specific feedback.

Image

  • Which feature do you want to improve? (and what problem does it have)

The feature to improve is the toast error notification system related to socket disconnections. The current implementation does not support editing or overriding the default error message, making it less informative or potentially confusing for end users.

  • What is the benefit of the enhancement?

This enhancement provides greater flexibility and control over user-facing messages. It enables developers to tailor error feedback based on the application’s context, improving UX and making debugging easier for end users.

  • Show an example/usecase were the improvement are needed.

In a chat application, when the socket connection fails, the current message might be: "Socket error occurred."
With this improvement, it can be customized to: "Connection lost. Trying to reconnect..." or "You have been disconnected. Please check your internet connection."

Additional context It could be added as a configuration parameter in rx.App or rx.Config.

lcastiglione avatar Apr 09 '25 10:04 lcastiglione

how do you expect the api for this to look like

adhami3310 avatar Apr 11 '25 07:04 adhami3310

how do you expect the api for this to look like

Hi adhami3310. What I'm thinking is that a parameter called api_error or api_error_msg could be added to rx.Config, which would accept a function that returns an error message. I chose a function because this would allow parameters to be passed and make the message more personalized.

Example:

import reflex as rx

config = rx.Config(
    app_name="myapp",
    api_url=os.getenv("API_URL"),
    api_error=lambda url: f"Connection to {url} lost. Trying to reconnect..."
)

If nothing is defined, the current default message remains.

lcastiglione avatar Apr 14 '25 12:04 lcastiglione

There should be a way to completely disable the toast. Also, it's probably nice to pass a component instead of a string.

benedikt-bartscher avatar Apr 15 '25 21:04 benedikt-bartscher

There should be a way to completely disable the toast. Also, it's probably nice to pass a component instead of a string.

@benedikt-bartscher I like the idea of being able to pass a custom component!!

lcastiglione avatar Apr 15 '25 22:04 lcastiglione

it would help me customize for non english users

Rubyer77 avatar Nov 08 '25 16:11 Rubyer77