abstract class ApiException implements Exception { final String message; final int? statusCode; const ApiException(this.message, {this.statusCode}); factory ApiException.fromDioError(Object error) { if (error is ApiException) return error; return ServerException('Request failed: ${error.toString()}'); } } class NetworkException extends ApiException { const NetworkException(super.message); } class ServerException extends ApiException { const ServerException(super.message, {super.statusCode}); } class UnauthorizedException extends ApiException { const UnauthorizedException([super.message = 'Authentication required']) : super(statusCode: 401); } class ValidationException extends ApiException { final Map? errors; const ValidationException(super.message, {this.errors, super.statusCode}); }