TF-1613 Implement handleSuccessViewState and handleFailureViewState for all controller
(cherry picked from commit 35e727e795bb3c44cc9c47e02542b5bdc3955fdd)
This commit is contained in:
@@ -8,6 +8,7 @@ abstract class RemoteException with EquatableMixin implements Exception {
|
||||
static const internalServerError = 'Internal Server Error';
|
||||
static const noNetworkError = 'No network error';
|
||||
static const badCredentials = 'Bad credentials';
|
||||
static const socketException = 'Socket exception';
|
||||
|
||||
final String? message;
|
||||
final int? code;
|
||||
@@ -36,6 +37,13 @@ class ConnectError extends RemoteException {
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class SocketError extends RemoteException {
|
||||
const SocketError() : super(message: RemoteException.socketException);
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class InternalServerError extends RemoteException {
|
||||
const InternalServerError() : super(message: RemoteException.internalServerError);
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:get/get_connect/http/src/status/http_status.dart';
|
||||
@@ -20,7 +22,7 @@ class RemoteExceptionThrower extends ExceptionThrower {
|
||||
throw const NoNetworkError();
|
||||
} else {
|
||||
if (error is DioError) {
|
||||
logError('RemoteExceptionThrower::throwException():type: ${error.type} | response: ${error.response}');
|
||||
logError('RemoteExceptionThrower::throwException():type: ${error.type} | response: ${error.response} | error: ${error.error}');
|
||||
switch (error.type) {
|
||||
case DioErrorType.connectionTimeout:
|
||||
throw const ConnectError();
|
||||
@@ -31,6 +33,8 @@ class RemoteExceptionThrower extends ExceptionThrower {
|
||||
throw BadGateway();
|
||||
} else if (error.response?.statusCode == HttpStatus.unauthorized) {
|
||||
throw const BadCredentialsException();
|
||||
} else if (error.error is SocketException) {
|
||||
throw const SocketError();
|
||||
} else {
|
||||
throw UnknownError(
|
||||
code: error.response?.statusCode,
|
||||
|
||||
Reference in New Issue
Block a user