use of com.androidnetworking.common.ANResponse in project Fast-Android-Networking by amitshekhariitbhu.
the class InternalRunnable method executeUploadRequest.
private void executeUploadRequest() {
Response okHttpResponse = null;
try {
okHttpResponse = InternalNetworking.performUploadRequest(request);
if (okHttpResponse == null) {
deliverError(request, Utils.getErrorForConnection(new ANError()));
return;
}
if (request.getResponseAs() == ResponseType.OK_HTTP_RESPONSE) {
request.deliverOkHttpResponse(okHttpResponse);
return;
}
if (okHttpResponse.code() >= 400) {
deliverError(request, Utils.getErrorForServerResponse(new ANError(okHttpResponse), request, okHttpResponse.code()));
return;
}
ANResponse response = request.parseResponse(okHttpResponse);
if (!response.isSuccess()) {
deliverError(request, response.getError());
return;
}
response.setOkHttpResponse(okHttpResponse);
request.deliverResponse(response);
} catch (Exception e) {
deliverError(request, Utils.getErrorForConnection(new ANError(e)));
} finally {
SourceCloseUtil.close(okHttpResponse, request);
}
}
use of com.androidnetworking.common.ANResponse in project Fast-Android-Networking by amitshekhariitbhu.
the class SynchronousCall method executeUploadRequest.
private static <T> ANResponse<T> executeUploadRequest(ANRequest request) {
Response okHttpResponse = null;
try {
okHttpResponse = InternalNetworking.performUploadRequest(request);
if (okHttpResponse == null) {
return new ANResponse<>(Utils.getErrorForConnection(new ANError()));
}
if (request.getResponseAs() == ResponseType.OK_HTTP_RESPONSE) {
ANResponse response = new ANResponse(okHttpResponse);
response.setOkHttpResponse(okHttpResponse);
return response;
}
if (okHttpResponse.code() >= 400) {
ANResponse response = new ANResponse<>(Utils.getErrorForServerResponse(new ANError(okHttpResponse), request, okHttpResponse.code()));
response.setOkHttpResponse(okHttpResponse);
return response;
}
ANResponse response = request.parseResponse(okHttpResponse);
response.setOkHttpResponse(okHttpResponse);
return response;
} catch (ANError se) {
return new ANResponse<>(Utils.getErrorForConnection(se));
} catch (Exception e) {
return new ANResponse<>(Utils.getErrorForNetworkOnMainThreadOrConnection(e));
} finally {
SourceCloseUtil.close(okHttpResponse, request);
}
}
Aggregations