Skip to content

Commit 130f58c

Browse files
authored
Merge pull request #10 from taboola/safe-clause-of-communication-interceptor
Adding safe exception handling from before/after external code parts
2 parents e7d9e63 + bd39404 commit 130f58c

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/main/java/com/taboola/rest/api/internal/interceptors/ImmutableRequestResponseInterceptor.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
import java.io.IOException;
77
import java.util.Objects;
88

9+
import org.apache.logging.log4j.LogManager;
10+
import org.apache.logging.log4j.Logger;
11+
912
import com.taboola.rest.api.model.CommunicationInterceptor;
1013

1114
/**
@@ -16,6 +19,7 @@
1619
*/
1720
public class ImmutableRequestResponseInterceptor implements Interceptor {
1821

22+
private static final Logger logger = LogManager.getLogger(ImmutableRequestResponseInterceptor.class);
1923
private final CommunicationInterceptor interceptor;
2024

2125
public ImmutableRequestResponseInterceptor(CommunicationInterceptor interceptor) {
@@ -25,13 +29,22 @@ public ImmutableRequestResponseInterceptor(CommunicationInterceptor interceptor)
2529

2630
@Override
2731
public Response intercept(Chain chain) throws IOException {
28-
interceptor.before(chain.request());
32+
try {
33+
interceptor.before(chain.request());
34+
} catch (Throwable t) {
35+
logger.error("Failed to execute 'before' communication interceptor", t);
36+
}
37+
2938
Response response = null;
3039
try {
3140
response = chain.proceed(chain.request());
3241
return response;
3342
} finally {
34-
interceptor.after(chain.request(), response);
43+
try {
44+
interceptor.after(chain.request(), response);
45+
} catch (Throwable t) {
46+
logger.error("Failed to execute 'after' communication interceptor", t);
47+
}
3548
}
3649
}
3750
}

0 commit comments

Comments
 (0)