feat(apps): add core API infrastructure
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
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});
|
||||
}
|
||||
Reference in New Issue
Block a user