Skip to content

Commit 7d3d718

Browse files
committed
Better logging
1 parent ddd525a commit 7d3d718

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/main/kotlin/com/ashampoo/imageproxy/Routing.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import kotlinx.coroutines.CompletableDeferred
3131
import kotlinx.coroutines.Dispatchers
3232
import kotlinx.coroutines.withContext
3333
import java.io.ByteArrayOutputStream
34+
import java.net.ConnectException
3435
import kotlin.math.max
3536
import kotlin.math.round
3637

@@ -84,11 +85,18 @@ fun Application.configureRouting() {
8485
return@get
8586
}
8687

87-
val response = httpClient.get(remoteUrl) {
88+
val response = try {
8889

89-
/* If set, pass the auth token on to the remote service */
90-
if (authToken != null)
91-
header(AUTHORIZATION_HEADER, authToken)
90+
httpClient.get(remoteUrl) {
91+
92+
/* If set, pass the auth token on to the remote service */
93+
if (authToken != null)
94+
header(AUTHORIZATION_HEADER, authToken)
95+
}
96+
97+
} catch (ex: ConnectException) {
98+
call.respond(HttpStatusCode.InternalServerError, "Failed to connect to $remoteUrl")
99+
return@get
92100
}
93101

94102
/* If the remote URL requires authorization we forward it as is. */

0 commit comments

Comments
 (0)