TF-196 Implement RemoteExceptionThrower when get session
This commit is contained in:
@@ -5,9 +5,20 @@ import 'package:dio/dio.dart';
|
||||
class RemoteExceptionThrower {
|
||||
void throwRemoteException(dynamic exception, {Function(DioError)? handler}) {
|
||||
if (exception is DioError) {
|
||||
handler != null ? handler(exception) : throw UnknownError(exception.message);
|
||||
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(exception.toString());
|
||||
throw UnknownError(message: exception.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,14 +2,23 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
abstract class RemoteException extends Equatable implements Exception {
|
||||
static final connectError = 'Connect error';
|
||||
|
||||
final String? message;
|
||||
final int? code;
|
||||
|
||||
RemoteException(this.message);
|
||||
RemoteException({this.code, this.message});
|
||||
}
|
||||
|
||||
class UnknownError extends RemoteException {
|
||||
UnknownError(String? message) : super(message);
|
||||
UnknownError({int? code, String? message}) : super(code: code, message: message);
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class ConnectError extends RemoteException {
|
||||
ConnectError() : super(message: RemoteException.connectError);
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
|
||||
Reference in New Issue
Block a user