Skip to content

Commit 9a989a6

Browse files
committed
refactor(sentry): standardize exceptions to prevent Sentry minification
1 parent a340cff commit 9a989a6

File tree

75 files changed

+1122
-303
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1122
-303
lines changed

core/lib/core.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export 'domain/exceptions/download_file_exception.dart';
2525
export 'data/extensions/options_extensions.dart';
2626
export 'domain/exceptions/web_session_exception.dart';
2727
export 'domain/exceptions/platform_exception.dart';
28+
export 'domain/exceptions/app_base_exception.dart';
2829

2930
// Utils
3031
export 'presentation/utils/theme_utils.dart';
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1+
import 'package:core/domain/exceptions/app_base_exception.dart';
12
import 'package:equatable/equatable.dart';
23

3-
class AddressException with EquatableMixin implements Exception {
4-
final String message;
5-
6-
AddressException(this.message);
4+
class AddressException extends AppBaseException with EquatableMixin {
5+
const AddressException(super.message);
76

87
@override
9-
String toString() => message;
8+
String get exceptionName => 'AddressException';
109

1110
@override
12-
List<Object> get props => [message];
11+
List<Object?> get props => [message, exceptionName];
1312
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
abstract class AppBaseException implements Exception {
2+
final String? message;
3+
4+
const AppBaseException([this.message]);
5+
6+
@override
7+
String toString() {
8+
if (message != null && message!.isNotEmpty) {
9+
return '$exceptionName: $message';
10+
}
11+
return exceptionName;
12+
}
13+
14+
String get exceptionName;
15+
}
Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
1+
import 'package:core/domain/exceptions/app_base_exception.dart';
12
import 'package:equatable/equatable.dart';
23

3-
abstract class DownloadFileException with EquatableMixin implements Exception {
4-
final String message;
5-
6-
DownloadFileException(this.message);
7-
8-
@override
9-
String toString() => message;
4+
abstract class DownloadFileException extends AppBaseException
5+
with EquatableMixin {
6+
const DownloadFileException(super.message);
107

118
@override
12-
List<Object> get props => [message];
9+
List<Object?> get props => [message, exceptionName];
1310
}
1411

1512
class CommonDownloadFileException extends DownloadFileException {
16-
CommonDownloadFileException(message) : super(message);
13+
const CommonDownloadFileException(super.message);
1714

1815
@override
19-
List<Object> get props => [message];
16+
String get exceptionName => 'CommonDownloadFileException';
2017
}
2118

2219
class CancelDownloadFileException extends DownloadFileException {
23-
CancelDownloadFileException(cancelMessage) : super(cancelMessage);
20+
const CancelDownloadFileException(super.message);
2421

2522
@override
26-
List<Object> get props => [message];
23+
String get exceptionName => 'CancelDownloadFileException';
2724
}
2825

2926
class DeviceNotSupportedException extends DownloadFileException {
30-
DeviceNotSupportedException() : super('This device is not supported, please try on Android or iOS');
31-
}
27+
const DeviceNotSupportedException()
28+
: super('This device is not supported, please try on Android or iOS');
29+
30+
@override
31+
String get exceptionName => 'DeviceNotSupportedException';
32+
}
Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1+
import 'package:core/domain/exceptions/app_base_exception.dart';
12
import 'package:equatable/equatable.dart';
23

3-
abstract class FileException with EquatableMixin implements Exception {
4-
final String message;
5-
6-
FileException(this.message);
7-
8-
@override
9-
String toString() => message;
4+
abstract class FileException extends AppBaseException with EquatableMixin {
5+
const FileException(super.message);
106

117
@override
12-
List<Object> get props => [message];
8+
List<Object?> get props => [message, exceptionName];
139
}
1410

1511
class NotFoundFileInFolderException extends FileException {
1612
NotFoundFileInFolderException() : super('No files found in the folder');
13+
14+
@override
15+
String get exceptionName => 'NotFoundFileInFolderException';
1716
}
1817

1918
class UserCancelShareFileException extends FileException {
2019
UserCancelShareFileException() : super('User cancel share file');
21-
}
20+
21+
@override
22+
String get exceptionName => 'UserCancelShareFileException';
23+
}
Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1+
import 'package:core/domain/exceptions/app_base_exception.dart';
12
import 'package:equatable/equatable.dart';
23

3-
class PlatformException with EquatableMixin implements Exception {
4-
final String message;
4+
class PlatformException extends AppBaseException with EquatableMixin {
5+
const PlatformException(super.message);
56

6-
PlatformException(this.message);
7+
@override
8+
String get exceptionName => 'PlatformException';
79

810
@override
9-
List<Object> get props => [message];
11+
List<Object?> get props => [message, exceptionName];
1012
}
1113

1214
class NoSupportPlatformException extends PlatformException {
13-
NoSupportPlatformException() : super('This platform is not supported');
14-
}
15+
const NoSupportPlatformException() : super('This platform is not supported');
16+
17+
@override
18+
String get exceptionName => 'NoSupportPlatformException';
19+
}
Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
class UnsupportedCharsetException implements Exception {
2-
const UnsupportedCharsetException();
1+
import 'package:core/domain/exceptions/app_base_exception.dart';
2+
3+
class UnsupportedCharsetException extends AppBaseException {
4+
const UnsupportedCharsetException([super.message]);
5+
6+
@override
7+
String get exceptionName => 'UnsupportedCharsetException';
38
}
49

5-
class NullCharsetException implements Exception {
6-
const NullCharsetException();
7-
}
10+
class NullCharsetException extends AppBaseException {
11+
const NullCharsetException([super.message]);
12+
13+
@override
14+
String get exceptionName => 'NullCharsetException';
15+
}
Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,44 @@
1+
import 'package:core/domain/exceptions/app_base_exception.dart';
12
import 'package:equatable/equatable.dart';
23

3-
class NotFoundInWebSessionException with EquatableMixin implements Exception {
4-
final String? errorMessage;
4+
class NotFoundInWebSessionException extends AppBaseException
5+
with EquatableMixin {
6+
const NotFoundInWebSessionException({String? errorMessage})
7+
: super(errorMessage);
58

6-
NotFoundInWebSessionException({this.errorMessage});
9+
@override
10+
String get exceptionName => 'NotFoundInWebSessionException';
711

812
@override
9-
List<Object> get props => [];
13+
List<Object?> get props => [message, exceptionName];
1014
}
1115

12-
class NotMatchInWebSessionException with EquatableMixin implements Exception {
13-
const NotMatchInWebSessionException();
16+
class NotMatchInWebSessionException extends AppBaseException
17+
with EquatableMixin {
18+
const NotMatchInWebSessionException() : super('Session data does not match');
19+
20+
@override
21+
String get exceptionName => 'NotMatchInWebSessionException';
1422

1523
@override
16-
List<Object> get props => [];
24+
List<Object?> get props => [message, exceptionName];
1725
}
1826

19-
class SaveToWebSessionFailException with EquatableMixin implements Exception {
20-
final String? errorMessage;
27+
class SaveToWebSessionFailException extends AppBaseException
28+
with EquatableMixin {
29+
const SaveToWebSessionFailException({String? errorMessage})
30+
: super(errorMessage);
2131

22-
SaveToWebSessionFailException({this.errorMessage});
32+
@override
33+
String get exceptionName => 'SaveToWebSessionFailException';
2334

2435
@override
25-
List<Object> get props => [];
36+
List<Object?> get props => [message, exceptionName];
2637
}
2738

28-
class CannotOpenNewWindowException implements Exception {}
39+
class CannotOpenNewWindowException extends AppBaseException {
40+
const CannotOpenNewWindowException([super.message]);
41+
42+
@override
43+
String get exceptionName => 'CannotOpenNewWindowException';
44+
}

core/lib/utils/file_utils.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class FileUtils {
3939

4040
return fileDirectory;
4141
} else {
42-
throw DeviceNotSupportedException();
42+
throw const DeviceNotSupportedException();
4343
}
4444
}
4545

core/lib/utils/logger/log_tracking.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class LogTracking {
130130

131131
return fileDirectory;
132132
} else {
133-
throw DeviceNotSupportedException();
133+
throw const DeviceNotSupportedException();
134134
}
135135
}
136136

0 commit comments

Comments
 (0)