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