TF-1613 Add InternalServerError to RemoteExceptionThrower
(cherry picked from commit 5f54d8e3975b42721f45d54ff44bec2ef6508911)
This commit is contained in:
@@ -5,6 +5,7 @@ import 'package:jmap_dart_client/jmap/core/error/method/error_method_response.da
|
|||||||
|
|
||||||
abstract class RemoteException with EquatableMixin implements Exception {
|
abstract class RemoteException with EquatableMixin implements Exception {
|
||||||
static const connectError = 'Connect error';
|
static const connectError = 'Connect error';
|
||||||
|
static const internalServerError = 'Internal Server Error';
|
||||||
static const noNetworkError = 'No network error';
|
static const noNetworkError = 'No network error';
|
||||||
static const badCredentials = 'Bad credentials';
|
static const badCredentials = 'Bad credentials';
|
||||||
|
|
||||||
@@ -35,6 +36,13 @@ class ConnectError extends RemoteException {
|
|||||||
List<Object> get props => [];
|
List<Object> get props => [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class InternalServerError extends RemoteException {
|
||||||
|
const InternalServerError() : super(message: RemoteException.internalServerError);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [];
|
||||||
|
}
|
||||||
|
|
||||||
class MethodLevelErrors extends RemoteException {
|
class MethodLevelErrors extends RemoteException {
|
||||||
final ErrorType type;
|
final ErrorType type;
|
||||||
|
|
||||||
|
|||||||
@@ -15,38 +15,40 @@ class RemoteExceptionThrower extends ExceptionThrower {
|
|||||||
throwException(dynamic error) {
|
throwException(dynamic error) {
|
||||||
logError('RemoteExceptionThrower::throwException():error: $error');
|
logError('RemoteExceptionThrower::throwException():error: $error');
|
||||||
final networkConnectionController = getBinding<NetworkConnectionController>();
|
final networkConnectionController = getBinding<NetworkConnectionController>();
|
||||||
if (networkConnectionController != null) {
|
if (networkConnectionController?.isNetworkConnectionAvailable() == false) {
|
||||||
if (!networkConnectionController.isNetworkConnectionAvailable()) {
|
logError('RemoteExceptionThrower::throwException():isNetworkConnectionAvailable');
|
||||||
throw const NoNetworkError();
|
throw const NoNetworkError();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (error is DioError) {
|
|
||||||
switch (error.type) {
|
|
||||||
case DioErrorType.connectionTimeout:
|
|
||||||
throw const ConnectError();
|
|
||||||
default:
|
|
||||||
if (error.response?.statusCode == 502) {
|
|
||||||
throw BadGateway();
|
|
||||||
} else if (error.response?.statusCode == HttpStatus.unauthorized) {
|
|
||||||
throw const BadCredentialsException();
|
|
||||||
} else {
|
|
||||||
throw UnknownError(
|
|
||||||
code: error.response?.statusCode,
|
|
||||||
message: error.response?.statusMessage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (error is ErrorMethodResponseException) {
|
|
||||||
final errorResponse = error.errorResponse as ErrorMethodResponse;
|
|
||||||
if (errorResponse is CannotCalculateChangesMethodResponse) {
|
|
||||||
throw CannotCalculateChangesMethodResponseException();
|
|
||||||
} else {
|
|
||||||
throw MethodLevelErrors(
|
|
||||||
errorResponse.type,
|
|
||||||
message: errorResponse.description);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
throw error;
|
if (error is DioError) {
|
||||||
|
logError('RemoteExceptionThrower::throwException():type: ${error.type} | response: ${error.response}');
|
||||||
|
switch (error.type) {
|
||||||
|
case DioErrorType.connectionTimeout:
|
||||||
|
throw const ConnectError();
|
||||||
|
default:
|
||||||
|
if (error.response?.statusCode == HttpStatus.internalServerError) {
|
||||||
|
throw const InternalServerError();
|
||||||
|
} else if (error.response?.statusCode == HttpStatus.badGateway) {
|
||||||
|
throw BadGateway();
|
||||||
|
} else if (error.response?.statusCode == HttpStatus.unauthorized) {
|
||||||
|
throw const BadCredentialsException();
|
||||||
|
} else {
|
||||||
|
throw UnknownError(
|
||||||
|
code: error.response?.statusCode,
|
||||||
|
message: error.response?.statusMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (error is ErrorMethodResponseException) {
|
||||||
|
final errorResponse = error.errorResponse as ErrorMethodResponse;
|
||||||
|
if (errorResponse is CannotCalculateChangesMethodResponse) {
|
||||||
|
throw CannotCalculateChangesMethodResponseException();
|
||||||
|
} else {
|
||||||
|
throw MethodLevelErrors(
|
||||||
|
errorResponse.type,
|
||||||
|
message: errorResponse.description);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user