handleResponse function
HzyNormalResponse
handleResponse({
- Response? response,
- HzyNormalTransFormer? hzyNormalTransFormer,
- int caCheStatusCode = 304,
Implementation
HzyNormalResponse handleResponse({
Response? response,
HzyNormalTransFormer? hzyNormalTransFormer,
int caCheStatusCode = 304,
}) {
hzyNormalTransFormer ??= HzyNormalDefaultTransFormer.getInstance();
if (response == null) {
return HzyNormalResponse.fail(
data: response,
errorMsg: '请求的数据为空',
errorCode: -1,
);
}
if (_isTokenTimeout(response.statusCode)) {
return HzyNormalResponse.failureFromError(
UnauthorisedException(
message: "没有权限",
code: response.statusCode,
data: response.data,
),
);
}
// 接口调用成功
if (_isRequestSuccess(
response.statusCode,
caCheStatusCode,
)) {
return hzyNormalTransFormer.parse(response);
} else {
// 接口调用失败
return HzyNormalResponse.fail(
errorMsg: response.statusMessage,
errorCode: response.statusCode,
data: response,
);
}
}