Various utils for OkHttp


License

License

GroupId

GroupId

dk.nodes.utils
ArtifactId

ArtifactId

okhttp
Last Version

Last Version

0.12.2
Release Date

Release Date

Type

Type

aar
Description

Description

Various utils for OkHttp
Various utils for OkHttp
Project URL

Project URL

https://github.com/nodes-android/okhttputils
Source Code Management

Source Code Management

https://github.com/nodes-android/okhttputils

Download okhttp

How to add to project

<!-- https://jarcasting.com/artifacts/dk.nodes.utils/okhttp/ -->
<dependency>
    <groupId>dk.nodes.utils</groupId>
    <artifactId>okhttp</artifactId>
    <version>0.12.2</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/dk.nodes.utils/okhttp/
implementation 'dk.nodes.utils:okhttp:0.12.2'
// https://jarcasting.com/artifacts/dk.nodes.utils/okhttp/
implementation ("dk.nodes.utils:okhttp:0.12.2")
'dk.nodes.utils:okhttp:aar:0.12.2'
<dependency org="dk.nodes.utils" name="okhttp" rev="0.12.2">
  <artifact name="okhttp" type="aar" />
</dependency>
@Grapes(
@Grab(group='dk.nodes.utils', module='okhttp', version='0.12.2')
)
libraryDependencies += "dk.nodes.utils" % "okhttp" % "0.12.2"
[dk.nodes.utils/okhttp "0.12.2"]

Dependencies

runtime (6)

Group / Artifact Type Version
com.squareup.retrofit2 : retrofit jar 2.6.0
com.squareup.retrofit2 : converter-gson jar 2.6.0
com.squareup.okhttp3 : okhttp jar 4.3.1
com.squareup.okhttp3 : logging-interceptor jar 4.3.1
com.google.code.gson : gson jar 2.8.5
org.jetbrains.kotlin : kotlin-stdlib-jdk7 jar 1.3.61

Project Modules

There are no modules declared in this project.

okhttputils

Contains various different utilities for the OkHttp library usable across multiple projects.

Installation

Remove the excludes if the libraries are not already present in your app (they most likely are :D)

implementation ('dk.nodes.utils:okhttp:0.12.2')
{
    exclude module: 'retrofit:2.1.0'
    exclude module: 'converter-gson:2.1.0'
    exclude module: 'okhttp:3.4.1'
    exclude module: 'gson:2.8.0'
}

HttpErrorManager

This is a global error handler for http requests performed by the OkHttp library. The idea is that instead of having to handle common error codes like 442 (invalid token) each place you make the request, you implement a handler for the error code once and for all.

There is no initialisation since the library use the firebase content provider trick to obtain a Context.

Usage

To show a message in a dialog when a certain error code is returned:

HttpErrorManager.setHandler(500, new HttpErrorHandler("Ach nein! eine internal server fehler has passiert!!!", true);

To show a message in a dialog and run some code after the user dismiss it:

HttpErrorHandler invalidAuthHandler = new HttpErrorHandler("Ach nein! deine Token sind KAPUT!!") {
        @Override
        public boolean onError(int code, String url) {
            // Only show dialog if the endpoint url does not contain the word login
            if(url.contains("login")) {
                return false;
            }
            return true;
        }

        @Override
        public void onDialogClosed() {
            // This code gets run after the user dismissed the dialog         
            Intent intent = new Intent(App.this, SplashActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        }
};

// register the handler above for error code 442 and 443
HttpErrorManager.setHandler(442, invalidAuthHandler);
HttpErrorManager.setHandler(443, invalidAuthHandler);

If the user returns true from the onError method the dialog is shown. If no dialog is shown the onDialogClosed function will not get called.

dk.nodes.utils

Nodes - Android

Versions

Version
0.12.2
0.12.1
0.11
0.10
0.9
0.8
0.6
0.5
0.4
0.3