fix: Prefer reusing AppBaseException instead of redefining the exception contract CacheException and RemoteException

This commit is contained in:
dab246
2026-03-09 10:27:16 +07:00
committed by Dat H. Pham
parent 236ad5f075
commit 8a21e35d1e
139 changed files with 344 additions and 325 deletions
@@ -0,0 +1,28 @@
import 'package:tmail_ui_user/main/exceptions/remote/remote_exception.dart';
class AuthenticationException extends RemoteException {
const AuthenticationException({super.message});
@override
String get exceptionName => 'AuthenticationException';
}
class BadCredentialsException extends AuthenticationException {
const BadCredentialsException() : super(message: 'Bad credentials');
@override
String get exceptionName => 'BadCredentialsException';
}
class RefreshTokenFailedException extends AuthenticationException {
RefreshTokenFailedException({
int code = 400,
String? message,
}) : super(
message: message ??
'Refresh token failed with status $code. Session invalid or revoked.',
);
@override
String get exceptionName => 'RefreshTokenFailedException';
}
@@ -0,0 +1,34 @@
import 'package:jmap_dart_client/jmap/core/error/error_type.dart';
import 'package:jmap_dart_client/jmap/core/error/method/error_method_response.dart';
import 'package:tmail_ui_user/main/exceptions/remote/remote_exception.dart';
class MethodLevelErrors extends RemoteException {
final ErrorType type;
const MethodLevelErrors(
this.type, {
String? message,
}) : super(message: message);
@override
String get exceptionName => 'MethodLevelErrors';
@override
String toString() {
return '$exceptionName(type: $type): $message';
}
@override
List<Object?> get props => [type, ...super.props];
}
class CannotCalculateChangesMethodResponseException extends MethodLevelErrors {
CannotCalculateChangesMethodResponseException({String? message})
: super(
ErrorMethodResponse.cannotCalculateChanges,
message: message,
);
@override
String get exceptionName => 'CannotCalculateChangesMethodResponseException';
}
@@ -0,0 +1,38 @@
import 'package:tmail_ui_user/main/exceptions/remote/remote_exception.dart';
class NetworkException extends RemoteException {
const NetworkException({super.message});
@override
String get exceptionName => 'NetworkException';
}
class NoNetworkError extends NetworkException {
const NoNetworkError() : super(message: 'No network connection');
@override
String get exceptionName => 'NoNetworkError';
}
class ConnectionError extends NetworkException {
const ConnectionError({String? message})
: super(message: message ?? 'Connection error');
@override
String get exceptionName => 'ConnectionError';
}
class ConnectionTimeout extends NetworkException {
const ConnectionTimeout({String? message})
: super(message: message ?? 'Connection timeout');
@override
String get exceptionName => 'ConnectionTimeout';
}
class SocketError extends NetworkException {
const SocketError() : super(message: 'Socket exception');
@override
String get exceptionName => 'SocketError';
}
@@ -0,0 +1,26 @@
import 'package:core/domain/exceptions/app_base_exception.dart';
abstract class RemoteException extends AppBaseException {
final int? code;
const RemoteException({
this.code,
String? message,
}) : super(message);
@override
String toString() {
if (code != null && message != null) {
return '$exceptionName(code: $code): $message';
}
if (code != null) {
return '$exceptionName(code: $code)';
}
return super.toString();
}
@override
List<Object?> get props => [code, ...super.props];
}
@@ -0,0 +1,16 @@
import 'package:tmail_ui_user/main/exceptions/remote/remote_exception.dart';
class ServerException extends RemoteException {
const ServerException({super.code, super.message});
@override
String get exceptionName => 'ServerException';
}
class InternalServerError extends ServerException {
const InternalServerError()
: super(message: 'Internal Server Error');
@override
String get exceptionName => 'InternalServerError';
}
@@ -0,0 +1,11 @@
import 'package:tmail_ui_user/main/exceptions/remote/remote_exception.dart';
class UnknownRemoteException extends RemoteException {
const UnknownRemoteException({
super.code,
super.message,
});
@override
String get exceptionName => 'UnknownRemoteException';
}