-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
79 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/main/java/com/brsanthu/googleanalytics/GoogleAnalyticsExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.brsanthu.googleanalytics; | ||
|
||
/** | ||
* Models a handler which can be used to handle exceptions thrown while sending GA requests to google. This can be set | ||
* as config parameter as below. | ||
* | ||
* <pre> | ||
* GoogleAnalytics propagatingGa = GoogleAnalytics.builder()withConfig( | ||
* new GoogleAnalyticsConfig().setExceptionHandler(new YourExceptionHandler()) | ||
* ).build(); | ||
* </pre> | ||
* | ||
* <p> | ||
* Library comes with following implementations. | ||
* <ul> | ||
* <li>{@link PropagatingExceptionHandler} which propagates the exceptions. | ||
* </ul> | ||
*/ | ||
@FunctionalInterface | ||
public interface GoogleAnalyticsExceptionHandler { | ||
void handle(Throwable t); | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/brsanthu/googleanalytics/PropagatingExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.brsanthu.googleanalytics; | ||
|
||
/** | ||
* Exception handler which propagates the exceptions instead of just logging. | ||
*/ | ||
public class PropagatingExceptionHandler implements GoogleAnalyticsExceptionHandler { | ||
|
||
@Override | ||
public void handle(Throwable t) { | ||
if (t instanceof RuntimeException) { | ||
throw (RuntimeException) t; | ||
} | ||
|
||
throw new GoogleAnalyticsException(t); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters