mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-17 13:53:41 +00:00
feat: api result add code (#96)
This commit is contained in:
1 parent
dbbbc204fb
commit
2e639e0fef
9 files changed
+130
-89
No files matched your search
@@ -70,15 +70,17 @@ Future<T> _parse<T>(
|
||||
try {
|
||||
var resp = await fetch();
|
||||
if (fromJsonT != null) {
|
||||
return Result<T>.fromJson(resp.data, fromJsonT).data as T;
|
||||
final result = Result<T>.fromJson(resp.data, fromJsonT);
|
||||
if (result.code == 0) {
|
||||
return result.data as T;
|
||||
} else {
|
||||
throw Exception(result);
|
||||
}
|
||||
} else {
|
||||
return null as T;
|
||||
}
|
||||
} on DioError catch (e) {
|
||||
if (e.response == null) {
|
||||
throw Exception("Server error");
|
||||
}
|
||||
throw Exception(Result.fromJson(e.response?.data, (_) => null).msg);
|
||||
throw Exception(Result(code: 1000, msg: e.message));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user