30 lines
851 B
Dart
30 lines
851 B
Dart
|
|
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<String, dynamic>? errors;
|
||
|
|
const ValidationException(super.message, {this.errors, super.statusCode});
|
||
|
|
}
|