requestBool function
请求数据,返回bool数据,接口调用成功就返回结果
Implementation
Future<void> requestBool(Future<Response> Function() request,
{Function(bool)? onSuccess,
Function(String?, String?)? onFail,
bool isThrowEx = true}) async {
try {
var response = await request();
if (response.statusCode == HttpStatus.ok) {
var json = response.data;
var result = ResultDto<String>.fromJsonT(json);
if (result.isSuccess()) {
onSuccess?.call(true);
} else {
if (isThrowEx) {
throw BizException(code: result.errorCode, message: result.message);
} else {
onSuccess?.call(false);
}
}
} else {
HttpPlatform.get.throwHandler?.handleStatusCode(response.statusCode);
}
} on Exception catch (ex) {
HttpPlatform.get.throwHandler?.handleError(ex, onFail: onFail);
}
}