getException static method
this function will get exception and convert it to exception object to convert it later to error message fastly
Implementation
static NetworkExceptions getException(dynamic error) {
if (error is Exception) {
try {
if (error is AuthException) {
// If error is AuthException
return _handleStatusBasedException(error.statusCode, error);
} else if (error is PostgrestException) {
// If error is PostgrestException
return _handleStatusBasedException(error.code);
} else if (error is FunctionException) {
// If error is FunctionException
return _handleStatusBasedException(error.status.toString());
} else if (error is SocketException) {
return const NetworkExceptions.noInternetConnection();
} else if (error is FormatException) {
return const NetworkExceptions.formatException();
} else {
return const NetworkExceptions.unexpectedError();
}
} catch (_) {
return const NetworkExceptions.unexpectedError();
}
} else {
if (error.toString().contains("is not a subtype of")) {
return const NetworkExceptions.unableToProcess();
} else {
return const NetworkExceptions.unexpectedError();
}
}
}