handleError function
String
handleError(- DioError error
)
Implementation
String handleError(DioError error) {
String errorDescription = "";
if (error is DioError) {
DioError dioError = error;
switch (dioError.type) {
case DioErrorType.CANCEL:
errorDescription = "Request to API server was cancelled";
break;
case DioErrorType.CONNECT_TIMEOUT:
errorDescription = "Connection timeout with API server";
break;
case DioErrorType.DEFAULT:
errorDescription =
"Connection to API server failed due to internet connection";
break;
case DioErrorType.RECEIVE_TIMEOUT:
errorDescription = "Receive timeout in connection with API server";
break;
case DioErrorType.RESPONSE:
errorDescription = error.response.data['message'];
break;
case DioErrorType.SEND_TIMEOUT:
errorDescription = "Send timeout in connection with API server";
break;
default:
errorDescription = "Send timeout in connection with API server";
break;
}
} else {
errorDescription = "Unexpected error occured";
}
return errorDescription;
}