I'm working on a Flutter web application and I'm having problems handling low level errors properly.
The application uses graphql-flutter, and it seems that any error is wrapped in a library OperationException
.
If you look closely, the exception contains a LinkException
, that itself contains a originalException
and that is a XMLHttpRequest error
.
No more information is provided here.
Looking at the same from the browser development tools, you can see it's an ERR_CONNECTION_REFUSED
because I purposely configured an incorrect URL to trigger this error.
Ideally, I should be able to discriminate and handle connection exceptions, from http errors, from graphql errors in different ways.
To some extent, I was able to at least handle some http status codes for authentication purposes by inspecting the exception
bool isGraphqlResultUnauthorized(QueryResult result) {
if (result.hasException) {
if (result.exception?.linkException is HttpLinkParserException) {
final httpException =
result.exception?.linkException as HttpLinkParserException;
if (httpException.response.statusCode == 401) {
return true;
}
}
}
return false;
}
All this being said, I'm stuck catching low level errors like timeouts, unknown hosts, connections refuses, etc, and have failed to find a way to retrieve more meaningful information about what's the real cause of the exception.
I would appreciate any tips on how to retrieve this information, as I don't seem to see a way to do it at the moment.
Thank you everyone