RetrofitRxErrorHandler
Hardening Retrofit RxJaxa API Layer against random errors
Install / Use
/learn @RobertZagorski/RetrofitRxErrorHandlerREADME
RetrofitRxErrorHandler
What is it?
RetrofitRxErrorHandler is an attempt to harden Retrofit HTTP API layer against random errors, like timeouts, 500 server errors caused due to server overload or accidental loss of networks (happening especially in mobile applications).
Who should use it?
Everyone who is using Retrofit combined with RxJava and experienced random errors when sending requests.
Usage
-
Import gradle dependency:
-
Add following lines to you project's main
build.gradle:buildscript { repositories { jcenter() } } -
Add a dependency to application
build.gradle:compile 'com.rzagorski:retrofitrxerrorhandler:1.1.0'
-
-
Build the strategy:
RxCallAdapter rxCallAdapter = new RxCallAdapter.Builder() .addBackoffStrategy(Exponential.init() .addThrowable(HttpException.class) .setMaxRetries(3).build()) .build(); -
Add it as Retrofit
CallAdapter.Factory:Retrofit retrofit = new Retrofit.Builder() .addCallAdapterFactory(new RxErrorHandingFactory(rxCallAdapter)) .build()
Options:
-
different backoff strategies (
Simple,Exponential)Simple.init().(...).build()or
Exponential.init().(...).build()
Common:
-
reactions to different
ThrowablesExponential.init() .addThrowable(HttpException.class) -
reactions to HTTP error codes
Exponential.init() .setResponseCode(500) -
exclusive or inclusive behaviour to
Throwablesor HTTP error codesExponential.init() .exclusive() -
maximum retry count (different for every added strategy)
Exponential.init() .addThrowable(HttpException.class) .setBase(2) .setMaxRetries(3) -
backup
Observable(executed before strategy delay and after every occurrence of error or HTTP response code)Exponential.init() .addObservable(backupObservable)
Exponential:
-
base of exponential function:
Exponential.init() (...) .setBase(2)
Examples
License
Copyright 2016 Robert Zagórski.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Related Skills
gh-issues
341.2kFetch GitHub issues, spawn sub-agents to implement fixes and open PRs, then monitor and address PR review comments. Usage: /gh-issues [owner/repo] [--label bug] [--limit 5] [--milestone v1.0] [--assignee @me] [--fork user/repo] [--watch] [--interval 5] [--reviews-only] [--cron] [--dry-run] [--model glm-5] [--notify-channel -1002381931352]
node-connect
341.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
oracle
341.2kBest practices for using the oracle CLI (prompt + file bundling, engines, sessions, and file attachment patterns).
tmux
341.2kRemote-control tmux sessions for interactive CLIs by sending keystrokes and scraping pane output.
