init cc
This commit is contained in:
79
lib/core/errors/exceptions.dart
Normal file
79
lib/core/errors/exceptions.dart
Normal file
@@ -0,0 +1,79 @@
|
||||
/// Base exception class for the application
|
||||
abstract class AppException implements Exception {
|
||||
final String message;
|
||||
final String? code;
|
||||
final dynamic originalError;
|
||||
|
||||
const AppException(
|
||||
this.message, {
|
||||
this.code,
|
||||
this.originalError,
|
||||
});
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'AppException: $message${code != null ? ' (Code: $code)' : ''}';
|
||||
}
|
||||
}
|
||||
|
||||
/// Network-related exceptions
|
||||
class NetworkException extends AppException {
|
||||
const NetworkException(
|
||||
super.message, {
|
||||
super.code,
|
||||
super.originalError,
|
||||
});
|
||||
}
|
||||
|
||||
/// Cache-related exceptions
|
||||
class CacheException extends AppException {
|
||||
const CacheException(
|
||||
super.message, {
|
||||
super.code,
|
||||
super.originalError,
|
||||
});
|
||||
}
|
||||
|
||||
/// Validation-related exceptions
|
||||
class ValidationException extends AppException {
|
||||
const ValidationException(
|
||||
super.message, {
|
||||
super.code,
|
||||
super.originalError,
|
||||
});
|
||||
}
|
||||
|
||||
/// Authentication-related exceptions
|
||||
class AuthException extends AppException {
|
||||
const AuthException(
|
||||
super.message, {
|
||||
super.code,
|
||||
super.originalError,
|
||||
});
|
||||
}
|
||||
|
||||
/// Server-related exceptions
|
||||
class ServerException extends AppException {
|
||||
final int? statusCode;
|
||||
|
||||
const ServerException(
|
||||
super.message, {
|
||||
this.statusCode,
|
||||
super.code,
|
||||
super.originalError,
|
||||
});
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'ServerException: $message${statusCode != null ? ' (Status: $statusCode)' : ''}${code != null ? ' (Code: $code)' : ''}';
|
||||
}
|
||||
}
|
||||
|
||||
/// Local storage exceptions
|
||||
class StorageException extends AppException {
|
||||
const StorageException(
|
||||
super.message, {
|
||||
super.code,
|
||||
super.originalError,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user