Skip to content

Commit

Permalink
improved error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardstock committed Feb 19, 2019
1 parent eb1479e commit ebe0a16
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ project build.gradle
```groovy
ext {
minterSdkVersion = "0.2.2"
minterSdkVersion = "0.2.3"
}
dependencies {
Expand Down
4 changes: 4 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release notes

## 0.2.3
- Added `removeHttpInterceptor` to `ApiService` client, for easy http request mocking
- Added `java.io.EOFException` as friend exception to `NetworkException`. Also added `IOException` and `IOError`

## 0.2.2
- Hotfix: logger Mint.tag() worked wrong with NPE. Fixed with dummy object on uninitialized logger.

Expand Down
16 changes: 8 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) by MinterTeam. 2018
* Copyright (C) by MinterTeam. 2019
* @link <a href="https://github.com/MinterTeam">Org Github</a>
* @link <a href="https://github.com/edwardstock">Maintainer Github</a>
*
Expand Down Expand Up @@ -29,7 +29,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
}
}
Expand Down Expand Up @@ -90,7 +90,7 @@ apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.bintray'

group = 'network.minter.android'
version = '0.2.2'
version = '0.2.3'

def libPath = ""
if(hasProperty("nativeLibPath")) {
Expand Down Expand Up @@ -247,19 +247,19 @@ dependencies {
compileOnly 'javax.annotation:jsr250-api:1.0'

// network
implementation 'com.squareup.okhttp3:okhttp:3.11.0'
implementation 'com.squareup.okhttp3:okhttp:3.12.1'
implementation 'com.squareup.okhttp3:logging-interceptor:3.9.0'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
implementation 'com.google.guava:guava:26.0-android'

implementation "com.madgag.spongycastle:core:${scastleVersion}"
implementation "com.madgag.spongycastle:prov:${scastleVersion}"

// stuff
implementation 'com.jakewharton.timber:timber:4.7.1'
implementation 'org.parceler:parceler-api:1.1.11'
annotationProcessor 'org.parceler:parceler:1.1.11'
implementation 'org.parceler:parceler-api:1.1.12'
annotationProcessor 'org.parceler:parceler:1.1.12'

// testing
testImplementation 'junit:junit:4.12'
Expand Down
10 changes: 6 additions & 4 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# Copyright (C) by MinterTeam. 2018
# @link https://github.com/MinterTeam
# @link https://github.com/edwardstock
# Copyright (C) by MinterTeam. 2019
# @link <a href="https://github.com/MinterTeam">Org Github</a>
# @link <a href="https://github.com/edwardstock">Maintainer Github</a>
#
# The MIT License
#
Expand All @@ -23,8 +23,10 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#

#Wed Jan 16 15:23:45 MSK 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-rc-1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
11 changes: 10 additions & 1 deletion src/main/java/network/minter/core/internal/api/ApiService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) by MinterTeam. 2018
* Copyright (C) by MinterTeam. 2019
* @link <a href="https://github.com/MinterTeam">Org Github</a>
* @link <a href="https://github.com/edwardstock">Maintainer Github</a>
*
Expand Down Expand Up @@ -128,6 +128,15 @@ public Builder addHttpInterceptor(Interceptor interceptor) {
return this;
}

public Builder removeHttpInterceptor(Interceptor interceptor) {
if (mInterceptors == null || interceptor == null) {
return this;
}

mInterceptors.remove(interceptor);
return this;
}

@Override
public Builder clone() {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) by MinterTeam. 2018
* Copyright (C) by MinterTeam. 2019
* @link <a href="https://github.com/MinterTeam">Org Github</a>
* @link <a href="https://github.com/edwardstock">Maintainer Github</a>
*
Expand All @@ -26,6 +26,9 @@

package network.minter.core.internal.exceptions;

import java.io.EOFException;
import java.io.IOError;
import java.io.IOException;
import java.net.ConnectException;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
Expand Down Expand Up @@ -55,6 +58,9 @@ public class NetworkException extends RuntimeException {
add(UnknownServiceException.class);
add(UnknownHostException.class);
add(ConnectException.class);
add(EOFException.class);
add(IOException.class);
add(IOError.class);
}};
private final Code mStatusCode;
private String mUserMessage;
Expand All @@ -77,9 +83,12 @@ public enum Code {
TimedOut(1001),
UnknownHost(1002),
UnknownService(1003),
HostUnreachable(1004);
HostUnreachable(1004),
UnexpectedEOF(1005),
UnexpectedIO(1006),
;

private int code = 1000;
private final int code;

Code(int c) {
code = c;
Expand Down Expand Up @@ -111,13 +120,7 @@ public NetworkException(Throwable another) {
mExceptionMessage = another.getMessage();
} else if (another instanceof UnknownHostException) {
mStatusCode = Code.UnknownHost;
// @TODO
// if (Dogsy.app().network().hasNetworkConnection()) {
// mUserMessage = "Ошибка сети. Попробуйте повторить операцию позднее.";
// } else {
mUserMessage = "Bad internet connection";
// }

mExceptionMessage = another.getMessage();
} else if (another instanceof UnknownServiceException) {
mStatusCode = Code.UnknownService;
Expand Down Expand Up @@ -152,6 +155,14 @@ public NetworkException(Throwable another) {
mStatusCode = Code.HostUnreachable;
mUserMessage = "Service unavailable. Please, try again later";
mExceptionMessage = another.getMessage();
} else if (another instanceof EOFException) {
mStatusCode = Code.UnexpectedEOF;
mUserMessage = "Unexpected server response: empty body";
mExceptionMessage = another.getMessage();
} else if (another instanceof IOException || another instanceof IOError) {
mStatusCode = Code.UnexpectedIO;
mUserMessage = "Input/Output error: " + another.getMessage();
mExceptionMessage = another.getMessage();
} else {
mStatusCode = Code.Unknown;
mUserMessage = "DecodeError network error. Please, try again later";
Expand Down

0 comments on commit ebe0a16

Please sign in to comment.