38 lines
990 B
Dart
38 lines
990 B
Dart
/// ============================================================
|
|
/// 闲言APP — API 异常定义
|
|
/// 创建时间: 2026-04-20
|
|
/// 更新时间: 2026-04-20
|
|
/// 作用: 统一网络/业务异常模型
|
|
/// 上次更新: 初始创建
|
|
/// ============================================================
|
|
|
|
/// API 异常
|
|
///
|
|
/// 封装错误码和用户友好的错误提示,
|
|
/// 供 UI 层统一展示 Toast / Snackbar。
|
|
class ApiException implements Exception {
|
|
const ApiException({
|
|
required this.code,
|
|
required this.message,
|
|
this.originalError,
|
|
});
|
|
|
|
/// 错误码 (HTTP 状态码或自定义业务码)
|
|
final int code;
|
|
|
|
/// 用户可读的错误提示
|
|
final String message;
|
|
|
|
/// 原始异常 (可选,调试用)
|
|
final dynamic originalError;
|
|
|
|
/// 是否为网络错误
|
|
bool get isNetworkError => code < 0;
|
|
|
|
/// 是否为授权错误
|
|
bool get isAuthError => code == 401;
|
|
|
|
@override
|
|
String toString() => 'ApiException(code: $code, message: $message)';
|
|
}
|