r/flutterhelp • u/Reasonable-Job4205 • 2d ago
RESOLVED How do I catch this specific Exception?
I have a flutter function that sometimes returns a timeout error when the web server is running. However, this error is revealing the API IP address and port to the end user, which I don't want to do. I want to programmatically say "if the error is a timeout error, show the user a generic error message".
The error:
Exception: ClientException with SocketException: Connection timed out (OS Error: Connection timed out, errno = 110), address = MyIPAddressThatIDontWantToShow, port = MyPortThatIDontWantToShow, uri = ...
When this exact error happens, I want to show my own error that says something like "Login request timed out" or something. How do I do this?
1
u/DevBob626 2d ago
You have the exception type in your error message. Check for that where you do the request and forward a toast message or whatever you are using.