feat(apps): add core API infrastructure

This commit is contained in:
qzl
2026-02-25 14:36:03 +08:00
parent 53c72e48e6
commit 75f4d2c3fb
6 changed files with 236 additions and 0 deletions
+29
View File
@@ -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});
}