Search in sources :

Example 6 with ANResponse

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);
    }
}
Also used : ANResponse(com.androidnetworking.common.ANResponse) Response(okhttp3.Response) ANError(com.androidnetworking.error.ANError) ANResponse(com.androidnetworking.common.ANResponse)

Example 7 with ANResponse

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);
    }
}
Also used : ANResponse(com.androidnetworking.common.ANResponse) Response(okhttp3.Response) ANError(com.androidnetworking.error.ANError) ANResponse(com.androidnetworking.common.ANResponse)

Aggregations

ANResponse (com.androidnetworking.common.ANResponse)7 Response (okhttp3.Response)7 ANError (com.androidnetworking.error.ANError)5 ANRequest (com.androidnetworking.common.ANRequest)2 AnalyticsListener (com.androidnetworking.interfaces.AnalyticsListener)2 DownloadProgressListener (com.androidnetworking.interfaces.DownloadProgressListener)2 User (com.networking.model.User)2 IOException (java.io.IOException)2 List (java.util.List)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2