This commit is contained in:
2023-08-30 14:44:58 +08:00
parent 8c655b0fd5
commit 6884beaf3d
14 changed files with 327 additions and 33 deletions

View File

@@ -19,4 +19,18 @@ class ApiResult<T> {
final String? error;
Map<String, dynamic> toJson(Object? Function(T) toJsonT) =>
_$ApiResultToJson(this, toJsonT);
T unwrap() {
if (ok) {
return data!;
} else {
return throw error!;
}
}
(int, String) unwrapErr() {
if (ok) {
return throw 'unwrap_err called on ok ApiResult';
} else {
return (status, error!);
}
}
}