This talk covers a real-world example of how Retrofit can be extended to solve app-wide problems by following the principle of Convention over Configuration.
Originally presented at the Auckland GDG (Google Developers Group).
create a CallAdapter.Factory to give to the Retrofit.Builder • Factories create CallAdapters for a given return type in the Service interface (e.g. Observable)
for interface methods that * return returnType, or null if it cannot be handled by * this factory. */ public abstract @Nullable CallAdapter<?, ?> get(Type returnType, Annotation[] annotations, Retrofit retrofit); // .. }
error” should be shown to the user: ◦ Internet Connection error ◦ Server error ◦ Unknown error (everything else) • The RxJavaCallAdapter just forwards low-level network Exceptions via onError()!
for interface methods that * return returnType, or null if it cannot be handled by * this factory. */ public abstract @Nullable CallAdapter<?, ?> get(Type returnType, Annotation[] annotations, Retrofit retrofit); // .. }
add to meds list... } override fun onCompleted() {} override fun onError(e: Throwable) { when (e) { is SocketTimeoutException -> showNoConnectionToServerError() is ConnectException -> showNoConnectionToServerError() is UnknownHostException -> showNoNetworkConnectionError() is HttpException -> makeSenseOfHttpResponseCode(e) else -> showGenericNetworkError() } } })