TF-1115 Add RemoteExceptionThrower
This commit is contained in:
@@ -15,8 +15,6 @@ export 'domain/extensions/media_type_extension.dart';
|
||||
// Exceptions
|
||||
export 'domain/exceptions/download_file_exception.dart';
|
||||
export 'data/extensions/options_extensions.dart';
|
||||
export 'domain/exceptions/remote_exception.dart';
|
||||
export 'data/network/remote_exception_thrower.dart';
|
||||
export 'domain/exceptions/web_session_exception.dart';
|
||||
|
||||
// Utils
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
|
||||
import 'package:core/domain/exceptions/remote_exception.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
class RemoteExceptionThrower {
|
||||
void throwRemoteException(dynamic exception, {Function(DioError)? handler}) {
|
||||
if (exception is DioError) {
|
||||
switch (exception.type) {
|
||||
case DioErrorType.connectTimeout:
|
||||
throw ConnectError();
|
||||
default:
|
||||
if (handler != null) {
|
||||
throw handler(exception);
|
||||
} else {
|
||||
throw UnknownError(
|
||||
code: exception.response?.statusCode,
|
||||
message: exception.message);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw UnknownError(message: exception.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
abstract class RemoteException extends Equatable implements Exception {
|
||||
static const connectError = 'Connect error';
|
||||
|
||||
final String? message;
|
||||
final int? code;
|
||||
|
||||
const RemoteException({this.code, this.message});
|
||||
}
|
||||
|
||||
class UnknownError extends RemoteException {
|
||||
const UnknownError({int? code, String? message}) : super(code: code, message: message);
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class ConnectError extends RemoteException {
|
||||
const ConnectError() : super(message: RemoteException.connectError);
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
Reference in New Issue
Block a user