Files
base_flutter/lib/core/errors/exceptions.dart
2025-09-26 18:48:14 +07:00

79 lines
1.6 KiB
Dart

/// 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,
});
}