diff --git a/.github/dependabot.yml b/.github/dependabot.yml
new file mode 100644
index 0000000..83eb023
--- /dev/null
+++ b/.github/dependabot.yml
@@ -0,0 +1,7 @@
+version: 2
+updates:
+ - package-ecosystem: github-actions
+ directory: /
+ schedule:
+ interval: monthly
+ rebase-strategy: disabled
diff --git a/.gitignore b/.gitignore
index a1996f1..698b725 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,4 @@
/local.properties
*.class
errorhandler-matchers/retrofit-rx-matcher/build/
+errorhandler-matchers/retrofit-rx-matcher/dist/
diff --git a/README.md b/README.md
index afdd276..a77a5dd 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,5 @@
# ErrorHandler
[ ](https://bintray.com/workable/maven/ErrorHandler/_latestVersion)
-[](https://bintray.com/workable/maven/ErrorHandler)
[](https://travis-ci.org/Workable/java-error-handler)
> Error handling library for Android and Java
@@ -13,7 +12,7 @@ Download the [latest JAR](https://bintray.com/workable/maven/ErrorHandler/_lates
com.workable
error-handler
- 1.0.0
+ 1.1.0
pom
```
@@ -21,7 +20,7 @@ Download the [latest JAR](https://bintray.com/workable/maven/ErrorHandler/_lates
or Gradle:
```groovy
-compile 'com.workable:error-handler:1.0.0'
+compile 'com.workable:error-handler:1.1.0'
```
@@ -50,12 +49,12 @@ ErrorHandler
// Bind HTTP 404 status to 404
.bind(404, errorCode -> throwable -> {
- return ((HttpException) throwable).code() == 404;
+ return throwable instanceof HttpException && ((HttpException) throwable).code() == 404;
})
// Bind HTTP 500 status to 500
.bind(500, errorCode -> throwable -> {
- return ((HttpException) throwable).code() == 500;
+ return throwable instanceof HttpException && ((HttpException) throwable).code() == 500;
})
// Bind all DB errors to a custom enumeration
diff --git a/build.gradle b/build.gradle
index 64a0847..14f5715 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,7 +1,8 @@
group 'com.workable'
-version '1.0.0'
+version '1.1.0'
apply plugin: 'java'
+apply plugin: 'maven-publish'
sourceCompatibility = 1.7
@@ -12,3 +13,28 @@ repositories {
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
}
+
+publishing {
+ publications {
+ mavenJava(MavenPublication) {
+ groupId 'com.workable'
+ artifactId 'parent'
+ version '1.1.0'
+ }
+ }
+
+ repositories {
+ maven {
+ url "./dist"
+ }
+ }
+}
+
+
+Properties localProps = new Properties()
+
+try {
+ localProps.load(project.file('local.properties').newDataInputStream())
+} catch(Exception ex) {
+ logger.warn('local.properties file is missing')
+}
\ No newline at end of file
diff --git a/errorhandler-matchers/README.md b/errorhandler-matchers/README.md
index cac729d..ee2ac1c 100644
--- a/errorhandler-matchers/README.md
+++ b/errorhandler-matchers/README.md
@@ -4,11 +4,19 @@ By default ErrorHandler provides you with a public, fully customizable MatcherFa
In order to use them, provide an instance of your desired MatcherFactory when building your ErrorHandler instances.
+## Usage
+
+### Retrofit-Rx-Matcher
+
+```gradle
+compile 'com.workable:retrofit-rx-matcher:1.1.0'
+```
+
```java
ErrorHandler
.create()
- .bindErrorCode(400, RetrofitMatcherFactory.create())
+ .bind(400, RetrofitMatcherFactory.create())
.on(400, (throwable, errorHandler) -> showErrorMessage("what?"))
.handle(httpException);
@@ -16,8 +24,8 @@ ErrorHandler
ErrorHandler
.create()
- .bindErrorCodeClass(Range.class, RetrofitMatcherFactory.createRange())
- .bindErrorCodeClass(Integer.class, RetrofitMatcherFactory.create())
+ .bindClass(Range.class, RetrofitMatcherFactory.createRange())
+ .bindClass(Integer.class, RetrofitMatcherFactory.create())
.on(400, (throwable, errorHandler) -> showErrorMessage("what?"))
.on(Range.of(500, 599), (throwable, errorHandler) -> showErrorMessage("kaboom"))
.handle(httpException);
diff --git a/errorhandler-matchers/retrofit-rx-matcher/build.gradle b/errorhandler-matchers/retrofit-rx-matcher/build.gradle
index 71c2a1f..e7a3275 100644
--- a/errorhandler-matchers/retrofit-rx-matcher/build.gradle
+++ b/errorhandler-matchers/retrofit-rx-matcher/build.gradle
@@ -1,7 +1,18 @@
+buildscript {
+ repositories {
+ jcenter()
+ }
+}
+
+plugins {
+ id "com.jfrog.bintray" version "1.7"
+}
+
group 'com.workable'
-version '1.0.0'
+version '1.1.0'
apply plugin: 'java'
+apply plugin: 'maven-publish'
sourceCompatibility = 1.7
@@ -16,3 +27,72 @@ dependencies {
compile project(':errorhandler')
compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
}
+
+task sourceJar(type: Jar) {
+ from sourceSets.main.allJava
+}
+
+task javadocJar(type: Jar) {
+ classifier = 'javadoc'
+ from javadoc
+}
+
+publishing {
+ publications {
+ mavenJava(MavenPublication) {
+ groupId 'com.workable'
+ artifactId 'retrofit-rx-matcher'
+ version '1.1.0'
+
+ from components.java
+
+ artifact sourceJar {
+ classifier "sources"
+ }
+
+ artifact javadocJar {
+ classifier "javadoc"
+ }
+ }
+ }
+
+ repositories {
+ maven {
+ url "./dist"
+ }
+ }
+}
+
+
+Properties localProps = new Properties()
+
+try {
+ localProps.load(project.file('../../local.properties').newDataInputStream())
+} catch(Exception ex) {
+ logger.warn('local.properties file is missing')
+}
+
+bintray {
+ user = localProps.getProperty('bintrayUser')
+ key = localProps.getProperty('bintrayApiKey')
+ publications = ['mavenJava']
+ pkg {
+ repo = 'maven'
+ name = 'ErrorHandler'
+ desc = 'Error handling library for Android and Java'
+ userOrg = "workable"
+ licenses = ['MIT']
+ vcsUrl = 'https://github.com/Workable/java-error-handler'
+ labels = ['java', 'error handler', 'errors', 'android']
+ publicDownloadNumbers = true
+ version {
+ name = '1.1.0'
+
+ desc = 'Error handling library for Android and Java'
+ vcsTag = 'v1.1.0'
+ gpg {
+ sign = true //Determines whether to GPG sign the files. The default is false
+ }
+ }
+ }
+}
diff --git a/errorhandler/build.gradle b/errorhandler/build.gradle
index 458799b..0a3086c 100644
--- a/errorhandler/build.gradle
+++ b/errorhandler/build.gradle
@@ -9,7 +9,7 @@ plugins {
}
group 'com.workable'
-version '1.0.0'
+version '1.1.0'
apply plugin: 'java'
apply plugin: 'maven-publish'
@@ -46,7 +46,7 @@ publishing {
mavenJava(MavenPublication) {
groupId 'com.workable'
artifactId 'error-handler'
- version '1.0.0'
+ version '1.1.0'
from components.java
@@ -90,10 +90,10 @@ bintray {
labels = ['java', 'error handler', 'errors', 'android']
publicDownloadNumbers = true
version {
- name = '1.0.0'
+ name = '1.1.0'
desc = 'Error handling library for Android and Java'
- vcsTag = 'v1.0.0'
+ vcsTag = 'v1.1.0'
gpg {
sign = true //Determines whether to GPG sign the files. The default is false
}
diff --git a/errorhandler/src/main/java/com/workable/errorhandler/ErrorHandler.java b/errorhandler/src/main/java/com/workable/errorhandler/ErrorHandler.java
index f2cee22..5d75b62 100644
--- a/errorhandler/src/main/java/com/workable/errorhandler/ErrorHandler.java
+++ b/errorhandler/src/main/java/com/workable/errorhandler/ErrorHandler.java
@@ -62,6 +62,12 @@ private ErrorHandler() {
this.otherwiseActions = new ArrayList<>();
this.alwaysActions = new ArrayList<>();
this.errorCodeMap = new HashMap<>();
+ this.localContext = new ThreadLocal(){
+ @Override
+ protected Context initialValue() {
+ return new Context();
+ }
+ };
}
/**
@@ -269,11 +275,11 @@ protected void handle(Throwable error, ThreadLocal context) {
*
* @param blockExecutor functional interface containing Exception prone code
*/
- protected void run(BlockExecutor blockExecutor) {
+ public void run(BlockExecutor blockExecutor) {
try {
blockExecutor.invoke();
} catch (Exception exception) {
- handle(exception);
+ handle(exception, localContext);
}
}
@@ -283,12 +289,7 @@ protected void run(BlockExecutor blockExecutor) {
* @param error the error as a {@link Throwable}
*/
public void handle(Throwable error) {
- this.handle(error, new ThreadLocal() {
- @Override
- protected Context initialValue() {
- return new Context();
- }
- });
+ this.handle(error, localContext);
}
/**
diff --git a/errorhandler/src/test/java/com/workable/errorhandler/ErrorHandlerTest.java b/errorhandler/src/test/java/com/workable/errorhandler/ErrorHandlerTest.java
index dbb047b..049666d 100644
--- a/errorhandler/src/test/java/com/workable/errorhandler/ErrorHandlerTest.java
+++ b/errorhandler/src/test/java/com/workable/errorhandler/ErrorHandlerTest.java
@@ -34,6 +34,8 @@ interface ActionDelegate {
void defaultAction2();
+ void defaultAction3();
+
void defaultOtherwise();
void defaultAlways();
@@ -62,6 +64,7 @@ protected void setUp() {
})
.on(FooException.class, (throwable, errorHandler) -> actionDelegateMock.defaultAction1())
.on(500, (throwable, errorHandler) -> actionDelegateMock.defaultAction2())
+ .on("closed:bar", (throwable, errorHandler) -> actionDelegateMock.defaultAction3())
.otherwise((throwable, errorHandler) -> actionDelegateMock.defaultOtherwise())
.always((throwable, errorHandler) -> actionDelegateMock.defaultAlways());
}
@@ -113,6 +116,7 @@ public void testActionsExecutionOrder() {
testVerifier2.verify(actionDelegateMock).action3();
testVerifier2.verify(actionDelegateMock).always1();
+ testVerifier2.verify(actionDelegateMock).defaultAction3();
testVerifier2.verify(actionDelegateMock).defaultAlways();
testVerifier2.verifyNoMoreInteractions();
Mockito.verifyNoMoreInteractions(actionDelegateMock);
@@ -278,6 +282,36 @@ public void testErrorHandlerBlockExecutorIgnoresNotMatchedException() {
Mockito.verifyNoMoreInteractions(actionDelegateMock);
}
+ @Test
+ public void testErrorHandlerIfSkipDefaults() {
+ InOrder testVerifier = inOrder(actionDelegateMock);
+
+ ErrorHandler
+ .create()
+ .skipDefaults()
+ .on("closed:bar", (throwable, handler) -> {
+ actionDelegateMock.action1();
+ })
+ .run(() -> {
+ throw new BarException("", false);
+ });
+
+ testVerifier.verify(actionDelegateMock).action1();
+ Mockito.verifyNoMoreInteractions(actionDelegateMock);
+
+ ErrorHandler
+ .create()
+ .on("closed:bar", (throwable, handler) -> {
+ actionDelegateMock.action2();
+ })
+ .run(() -> {
+ throw new BarException("", false);
+ });
+
+ testVerifier.verify(actionDelegateMock).action2();
+ testVerifier.verify(actionDelegateMock).defaultAction3();
+ }
+
private enum DBError {
READ_ONLY,
DEADLOCK,