refactor(sentry): standardize exceptions to prevent Sentry minification

This commit is contained in:
dab246
2026-02-24 15:40:07 +07:00
committed by Dat H. Pham
parent 296548a781
commit 2e8a11e7eb
75 changed files with 1128 additions and 309 deletions
@@ -1,9 +1,36 @@
class CanNotFoundOIDCAuthority implements Exception {}
import 'package:core/domain/exceptions/app_base_exception.dart';
class CanNotFoundOIDCLinks implements Exception {}
class CanNotFoundOIDCAuthority extends AppBaseException {
CanNotFoundOIDCAuthority([super.message]);
class CanNotFindToken implements Exception {}
@override
String get exceptionName => 'CanNotFoundOIDCAuthority';
}
class CanRetryOIDCException implements Exception {}
class CanNotFoundOIDCLinks extends AppBaseException {
CanNotFoundOIDCLinks([super.message]);
class NotFoundUserInfoEndpointException implements Exception {}
@override
String get exceptionName => 'CanNotFoundOIDCLinks';
}
class CanNotFindToken extends AppBaseException {
CanNotFindToken([super.message]);
@override
String get exceptionName => 'CanNotFindToken';
}
class CanRetryOIDCException extends AppBaseException {
CanRetryOIDCException([super.message]);
@override
String get exceptionName => 'CanRetryOIDCException';
}
class NotFoundUserInfoEndpointException extends AppBaseException {
NotFoundUserInfoEndpointException([super.message]);
@override
String get exceptionName => 'NotFoundUserInfoEndpointException';
}
@@ -1,4 +1,4 @@
import 'package:core/domain/exceptions/app_base_exception.dart';
import 'package:tmail_ui_user/main/exceptions/remote_exception.dart';
abstract class AuthenticationException extends RemoteException {
@@ -11,37 +11,94 @@ abstract class AuthenticationException extends RemoteException {
class BadCredentials extends AuthenticationException {
BadCredentials() : super(AuthenticationException.wrongCredential);
@override
String get exceptionName => 'BadCredentials';
}
class BadGateway extends AuthenticationException {
BadGateway() : super(AuthenticationException.badGateway);
@override
String get exceptionName => 'BadGateway';
}
class NotFoundAuthenticatedAccountException implements Exception {}
class NotFoundStoredTokenException implements Exception {}
class InvalidBaseUrl extends AuthenticationException {
InvalidBaseUrl() : super(AuthenticationException.invalidBaseUrl);
@override
String get exceptionName => 'InvalidBaseUrl';
}
class AccessTokenInvalidException implements Exception {}
class NotFoundAuthenticatedAccountException extends AppBaseException {
NotFoundAuthenticatedAccountException([super.message]);
class DownloadAttachmentHasTokenExpiredException implements Exception {
@override
String get exceptionName => 'NotFoundAuthenticatedAccountException';
}
class NotFoundStoredTokenException extends AppBaseException {
NotFoundStoredTokenException([super.message]);
@override
String get exceptionName => 'NotFoundStoredTokenException';
}
class AccessTokenInvalidException extends AppBaseException {
AccessTokenInvalidException([super.message]);
@override
String get exceptionName => 'AccessTokenInvalidException';
}
class DownloadAttachmentHasTokenExpiredException extends AppBaseException {
final String refreshToken;
DownloadAttachmentHasTokenExpiredException(this.refreshToken);
DownloadAttachmentHasTokenExpiredException(this.refreshToken)
: super('Token expired for refresh token: $refreshToken');
@override
String get exceptionName => 'DownloadAttachmentHasTokenExpiredException';
}
class CanNotFoundBaseUrl implements Exception {}
class CanNotFoundBaseUrl extends AppBaseException {
CanNotFoundBaseUrl([super.message]);
class CanNotFoundUserName implements Exception {}
@override
String get exceptionName => 'CanNotFoundBaseUrl';
}
class CanNotFoundPassword implements Exception {}
class CanNotFoundUserName extends AppBaseException {
CanNotFoundUserName([super.message]);
class NotFoundAuthenticationInfoCache implements Exception {}
@override
String get exceptionName => 'CanNotFoundUserName';
}
class CanNotFoundSaasServerUrl implements Exception {}
class CanNotFoundPassword extends AppBaseException {
CanNotFoundPassword([super.message]);
class SaasServerUriIsNull implements Exception {}
@override
String get exceptionName => 'CanNotFoundPassword';
}
class NotFoundAuthenticationInfoCache extends AppBaseException {
NotFoundAuthenticationInfoCache([super.message]);
@override
String get exceptionName => 'NotFoundAuthenticationInfoCache';
}
class CanNotFoundSaasServerUrl extends AppBaseException {
CanNotFoundSaasServerUrl([super.message]);
@override
String get exceptionName => 'CanNotFoundSaasServerUrl';
}
class SaasServerUriIsNull extends AppBaseException {
SaasServerUriIsNull([super.message]);
@override
String get exceptionName => 'SaasServerUriIsNull';
}
@@ -1,16 +1,35 @@
import 'package:flutter/services.dart';
import 'package:core/domain/exceptions/app_base_exception.dart';
class NotFoundDataResourceRecordException implements Exception {}
class NotFoundDataResourceRecordException extends AppBaseException {
NotFoundDataResourceRecordException([super.message]);
class NotFoundUrlException implements Exception {}
@override
String get exceptionName => 'NotFoundDataResourceRecordException';
}
class InvalidOIDCResponseException implements Exception {}
class NotFoundUrlException extends AppBaseException {
NotFoundUrlException([super.message]);
class NoSuitableBrowserForOIDCException implements Exception {
@override
String get exceptionName => 'NotFoundUrlException';
}
class InvalidOIDCResponseException extends AppBaseException {
InvalidOIDCResponseException([super.message]);
@override
String get exceptionName => 'InvalidOIDCResponseException';
}
class NoSuitableBrowserForOIDCException extends AppBaseException {
static const noBrowserAvailableCode = 'no_browser_available';
NoSuitableBrowserForOIDCException([super.message]);
@override
String get exceptionName => 'NoSuitableBrowserForOIDCException';
static bool verifyException(dynamic exception) {
if (exception is PlatformException) {
if (exception.code == noBrowserAvailableCode) {
@@ -21,5 +40,9 @@ class NoSuitableBrowserForOIDCException implements Exception {
}
}
class NotFoundCompanyServerLoginInfoException implements Exception {}
class NotFoundCompanyServerLoginInfoException extends AppBaseException {
NotFoundCompanyServerLoginInfoException([super.message]);
@override
String get exceptionName => 'NotFoundCompanyServerLoginInfoException';
}
@@ -1 +1,8 @@
class UserCancelledLogoutOIDCFlowException implements Exception {}
import 'package:core/domain/exceptions/app_base_exception.dart';
class UserCancelledLogoutOIDCFlowException extends AppBaseException {
UserCancelledLogoutOIDCFlowException([super.message]);
@override
String get exceptionName => 'UserCancelledLogoutOIDCFlowException';
}
@@ -1,15 +1,27 @@
class OAuthAuthorizationError {
import 'package:core/domain/exceptions/app_base_exception.dart';
class OAuthAuthorizationError extends AppBaseException {
static const String serverError = 'server_error'; // HTTP 500 error code
static const String temporarilyUnavailable =
'temporarily_unavailable'; // HTTP 503 error code
final String error;
final String? errorDescription;
const OAuthAuthorizationError({
required this.error,
this.errorDescription,
});
String? errorDescription,
}) : super(errorDescription);
@override
String get exceptionName => 'OAuthAuthorizationError';
@override
String toString() {
if (message != null && message!.isNotEmpty) {
return '$exceptionName(code: $error): $message';
}
return '$exceptionName(code: $error)';
}
static OAuthAuthorizationError fromErrorCode(
String error, {
@@ -30,11 +42,23 @@ class OAuthAuthorizationError {
}
class ServerError extends OAuthAuthorizationError {
const ServerError({super.errorDescription})
: super(error: OAuthAuthorizationError.serverError);
const ServerError({String? errorDescription})
: super(
error: OAuthAuthorizationError.serverError,
errorDescription: errorDescription,
);
@override
String get exceptionName => 'ServerError';
}
class TemporarilyUnavailable extends OAuthAuthorizationError {
const TemporarilyUnavailable({super.errorDescription})
: super(error: OAuthAuthorizationError.temporarilyUnavailable);
const TemporarilyUnavailable({String? errorDescription})
: super(
error: OAuthAuthorizationError.temporarilyUnavailable,
errorDescription: errorDescription,
);
@override
String get exceptionName => 'TemporarilyUnavailable';
}