GithubHelp home page GithubHelp logo

retrofiterror's Introduction

RetrofitError

Simple http service error handler, to be able get error as HttpException, IOException or something different, convert to human readable texts those given from user and also handle session logout states.

Prerequisites

First, dependency must be added to build.gradle file.

implementation 'nurisezgin.com.retrofiterror:retrofiterror:1.0.1'

How To Use

  • Use with Rx2Java, change Rx2 call adapter factory with Rx2RetrofitErrorCallAdapterFactory
    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(webServer.url("/"))
            .addCallAdapterFactory(Rx2RetrofitErrorCallAdapterFactory.create())
            .build();
  • Set customized actions to RetrofitErrorPlugin. There are session logout action, error converter and error adapter. (If you don't put any of them default methods will be run) Default error converter and session logout action are empty, they won't any side effect on application but DefaultErrorAdapter covers something, it handles an exception and triggers conversion actions over ErrorConverter and it can call specific SessionLogoutAction or default session logout action.
    RetrofitErrorPlugin.setDefaultSessionLogoutAction(action);
    RetrofitErrorPlugin.setErrorConverter(errorConverter);
    RetrofitErrorPlugin.setErrorAdapter(errorAdapter);
  • As service interface, in below example method of getUserFees using default session action but other methods use customized actions.
    interface Service {

        @DoOnSessionLogout(CustomAction.class)
        @GET("/balance")
        Observable<String> getUserBalance();

        @DoOnSessionLogout(CustomAction.class)
        @GET("/rawbalance")
        Observable<String> getRawUserBalance();

        @GET("/fees")
        Observable<String> getUserFees();

    }
  • Must use empty constructor in which class has been implemented in SessionLogoutAction
    public static class SimpleAction implements SessionLogoutAction {

        @Override
        public void onSessionLoggedOut(Request request) { }
    }

Authors

Licence

Copyright 2018 Nuri SEZGİN

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.

retrofiterror's People

Contributors

anurisezgin avatar acnnurisezgin avatar

Watchers

James Cloos avatar Gökhan Alıcı avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.