NetException.fromObj constructor
NetException.fromObj(
- Object e
Implementation
factory NetException.fromObj(Object e) {
if (e is NetException) {
return e;
} else if (e is DioError) {
switch (e.type) {
case DioErrorType.connectTimeout:
case DioErrorType.receiveTimeout:
case DioErrorType.sendTimeout:
return const NetException.timeout();
case DioErrorType.response:
switch (e.response?.statusCode) {
case 400:
return const NetException.badRequest();
case 401:
return const NetException.unauthorisedRequest();
case 404:
return const NetException.notFound();
case 500:
return const NetException.internalServerError();
case 503:
return const NetException.serviceUnavailable();
default:
var responseCode = e.response?.statusCode;
return NetException.defaultError(
'Received invalid status code: $responseCode');
}
default:
return const NetException.unexpectedError();
}
} else if (e is SocketException) {
return const NetException.noInternetConnection();
} else if (e is FormatException) {
return const NetException.formatException();
}
return const NetException.unexpectedError();
}