-
Notifications
You must be signed in to change notification settings - Fork 812
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Interceptor for IOExceptions generated by OKHttp and wrapped as…
… runtime exceptions
- Loading branch information
1 parent
6e53623
commit cdcfcd4
Showing
3 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
...c/main/java/io/opentelemetry/exporter/sender/okhttp/internal/IOeExceptionInterceptor.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,33 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.exporter.sender.okhttp.internal; | ||
|
||
import java.io.IOException; | ||
import okhttp3.Interceptor; | ||
import okhttp3.Response; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* Unwrapper of IOExceptions generated by the OkHttp requests. | ||
* | ||
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change | ||
* at any time. | ||
*/ | ||
public class IOeExceptionInterceptor implements Interceptor { | ||
@NotNull | ||
@Override | ||
public Response intercept(@NotNull Chain chain) throws IOException { | ||
try { | ||
return chain.proceed(chain.request()); | ||
} catch (Throwable e) { | ||
Throwable exceptionCause = e.getCause(); | ||
if (exceptionCause instanceof IOException) { | ||
throw (IOException) exceptionCause; | ||
} | ||
throw e; | ||
} | ||
} | ||
} |
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