Java Code Examples for com.lzy.okgo.model.Response#isSuccessful()
The following examples show how to use
com.lzy.okgo.model.Response#isSuccessful() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BodyOnSubscribe.java From okhttp-OkGo with Apache License 2.0 | 6 votes |
@Override public void onNext(Response<R> response) { if (response.isSuccessful()) { subscriber.onNext(response.body()); } else { subscriberTerminated = true; Throwable t = new HttpException(response); try { subscriber.onError(t); } catch (OnCompletedFailedException | OnErrorFailedException | OnErrorNotImplementedException e) { RxJavaHooks.getOnError().call(e); } catch (Throwable inner) { Exceptions.throwIfFatal(inner); RxJavaHooks.getOnError().call(new CompositeException(t, inner)); } } }
Example 2
Source File: DefaultCachePolicy.java From okhttp-OkGo with Apache License 2.0 | 6 votes |
@Override public Response<T> requestSync(CacheEntity<T> cacheEntity) { try { prepareRawCall(); } catch (Throwable throwable) { return Response.error(false, rawCall, null, throwable); } Response<T> response = requestNetworkSync(); //HTTP cache protocol if (response.isSuccessful() && response.code() == 304) { if (cacheEntity == null) { response = Response.error(true, rawCall, response.getRawResponse(), CacheException.NON_AND_304(request.getCacheKey())); } else { response = Response.success(true, cacheEntity.getData(), rawCall, response.getRawResponse()); } } return response; }
Example 3
Source File: FirstCacheRequestPolicy.java From okhttp-OkGo with Apache License 2.0 | 6 votes |
@Override public Response<T> requestSync(CacheEntity<T> cacheEntity) { try { prepareRawCall(); } catch (Throwable throwable) { return Response.error(false, rawCall, null, throwable); } //同步请求,不能返回两次,只返回正确的数据 Response<T> response; if (cacheEntity != null) { response = Response.success(true, cacheEntity.getData(), rawCall, null); } response = requestNetworkSync(); if (!response.isSuccessful() && cacheEntity != null) { response = Response.success(true, cacheEntity.getData(), rawCall, response.getRawResponse()); } return response; }
Example 4
Source File: DefaultCachePolicy.java From BaseProject with Apache License 2.0 | 6 votes |
@Override public Response<T> requestSync(CacheEntity<T> cacheEntity) { try { prepareRawCall(); } catch (Throwable throwable) { return Response.error(false, rawCall, null, throwable); } Response<T> response = requestNetworkSync(); //HTTP cache protocol if (response.isSuccessful() && response.code() == 304) { if (cacheEntity == null) { response = Response.error(true, rawCall, response.getRawResponse(), CacheException.NON_AND_304(request.getCacheKey())); } else { response = Response.success(true, cacheEntity.getData(), rawCall, response.getRawResponse()); } } return response; }
Example 5
Source File: FirstCacheRequestPolicy.java From BaseProject with Apache License 2.0 | 6 votes |
@Override public Response<T> requestSync(CacheEntity<T> cacheEntity) { try { prepareRawCall(); } catch (Throwable throwable) { return Response.error(false, rawCall, null, throwable); } //同步请求,不能返回两次,只返回正确的数据 Response<T> response; if (cacheEntity != null) { response = Response.success(true, cacheEntity.getData(), rawCall, null); } response = requestNetworkSync(); if (!response.isSuccessful() && cacheEntity != null) { response = Response.success(true, cacheEntity.getData(), rawCall, response.getRawResponse()); } return response; }
Example 6
Source File: BodyObservable.java From okhttp-OkGo with Apache License 2.0 | 5 votes |
@Override public void onNext(Response<R> response) { if (response.isSuccessful()) { observer.onNext(response.body()); } else { terminated = true; Throwable t = new HttpException(response); try { observer.onError(t); } catch (Throwable inner) { Exceptions.throwIfFatal(inner); RxJavaPlugins.onError(new CompositeException(t, inner)); } } }
Example 7
Source File: UploadTask.java From okhttp-OkGo with Apache License 2.0 | 5 votes |
@Override public void run() { progress.status = Progress.LOADING; postLoading(progress); final Response<T> response; try { //noinspection unchecked Request<T, ? extends Request> request = (Request<T, ? extends Request>) progress.request; final Call rawCall = request.getRawCall(); request.uploadInterceptor(new ProgressRequestBody.UploadInterceptor() { @Override public void uploadProgress(Progress innerProgress) { if (rawCall.isCanceled()) return; if (progress.status != Progress.LOADING) { rawCall.cancel(); return; } progress.from(innerProgress); postLoading(progress); } }); response = request.adapt().execute(); } catch (Exception e) { postOnError(progress, e); return; } if (response.isSuccessful()) { postOnFinish(progress, response.body()); } else { postOnError(progress, response.getException()); } }
Example 8
Source File: RequestFailedCachePolicy.java From okhttp-OkGo with Apache License 2.0 | 5 votes |
@Override public Response<T> requestSync(CacheEntity<T> cacheEntity) { try { prepareRawCall(); } catch (Throwable throwable) { return Response.error(false, rawCall, null, throwable); } Response<T> response = requestNetworkSync(); if (!response.isSuccessful() && cacheEntity != null) { response = Response.success(true, cacheEntity.getData(), rawCall, response.getRawResponse()); } return response; }
Example 9
Source File: RequestFailedCachePolicy.java From BaseProject with Apache License 2.0 | 5 votes |
@Override public Response<T> requestSync(CacheEntity<T> cacheEntity) { try { prepareRawCall(); } catch (Throwable throwable) { return Response.error(false, rawCall, null, throwable); } Response<T> response = requestNetworkSync(); if (!response.isSuccessful() && cacheEntity != null) { response = Response.success(true, cacheEntity.getData(), rawCall, response.getRawResponse()); } return response; }