networking and error handling

This commit is contained in:
amirrezaghabeli
2025-08-12 14:40:49 +03:30
parent 382ed4a2d6
commit 4aeb9229a4
14 changed files with 477 additions and 205 deletions
+92 -5
View File
@@ -1,8 +1,15 @@
class AppException implements Exception {
final String message;
final String prefix;
final int? statusCode;
final dynamic originalError;
AppException([this.message = 'An unknown error occurred.', this.prefix = '']);
AppException([
this.message = 'An unknown error occurred.',
this.prefix = '',
this.statusCode,
this.originalError,
]);
@override
String toString() {
@@ -11,11 +18,91 @@ class AppException implements Exception {
}
class FetchDataException extends AppException {
FetchDataException([String? message])
: super(message ?? 'Error During Communication: ', 'Network Error');
FetchDataException([String? message, int? statusCode, originalError])
: super(
message ?? 'Error During Communication: ',
'Network Error',
statusCode,
originalError,
);
}
class AuthenticationException extends AppException {
AuthenticationException([String? message])
: super(message ?? 'Authentication Failed.', 'Auth Error');
AuthenticationException([String? message, int? statusCode, originalError])
: super(
message ?? 'Authentication Failed.',
'Auth Error: ',
statusCode,
originalError,
);
}
class NetworkConnectionException extends AppException {
NetworkConnectionException([String? message, originalError])
: super(
message ?? 'No internet connection available.',
'Connection Error: ',
null,
originalError,
);
}
class TimeoutException extends AppException {
TimeoutException([String? message, originalError])
: super(
message ?? 'Request timed out.',
'Timeout Error: ',
null,
originalError,
);
}
class ServerException extends AppException {
ServerException([String? message, int? statusCode, originalError])
: super(
message ?? 'Server error occurred.',
'Server Error: ',
statusCode,
originalError,
);
}
class BadRequestException extends AppException {
BadRequestException([String? message, int? statusCode, originalError])
: super(
message ?? 'Bad request.',
'Bad Request Error: ',
statusCode,
originalError,
);
}
class NotFoundException extends AppException {
NotFoundException([String? message, int? statusCode, originalError])
: super(
message ?? 'Resource not found.',
'Not Found Error: ',
statusCode,
originalError,
);
}
class ForbiddenException extends AppException {
ForbiddenException([String? message, int? statusCode, originalError])
: super(
message ?? 'Access forbidden.',
'Forbidden Error: ',
statusCode,
originalError,
);
}
class RateLimitException extends AppException {
RateLimitException([String? message, int? statusCode, originalError])
: super(
message ?? 'Rate limit exceeded.',
'Rate Limit Error: ',
statusCode,
originalError,
);
}