Skip to content

Commit d9fb27d

Browse files
committed
update the error message of file not found from the HTTP request to be more descriptive rather than only the file path
1 parent e303cee commit d9fb27d

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ _Changes since 1.7.3_
2020
- The copying content of the above two copy functions now includes the request name and example name as the heading
2121
- Variables inherited from the Base example are now resolved in the Request Body Editor
2222
- Mouse hovering the Duration label in the Response Viewer now shows the flight start and end date time
23+
- The error message of file not found from the HTTP request has been improved
2324

2425
### Fixed
2526
- Crash when renaming a project

src/jvmMain/kotlin/com/sunnychung/application/multiplatform/hellohttp/network/SpringWebClientTransportClient.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import org.springframework.util.LinkedMultiValueMap
3838
import org.springframework.web.reactive.function.BodyInserter
3939
import org.springframework.web.reactive.function.BodyInserters
4040
import org.springframework.web.reactive.function.client.WebClient
41+
import org.springframework.web.reactive.function.client.WebClientRequestException
4142
import org.springframework.web.reactive.function.client.awaitBodyOrNull
4243
import org.springframework.web.reactive.function.client.awaitExchangeOrNull
4344
import reactor.core.publisher.Flux
@@ -46,6 +47,7 @@ import reactor.netty.http.client.HttpClientRequest
4647
import reactor.netty.http.client.HttpClientResponse
4748
import java.io.File
4849
import java.io.FileInputStream
50+
import java.nio.file.NoSuchFileException
4951

5052
@Reflection private val DefaultClientResponseClass = Class.forName("org.springframework.web.reactive.function.client.DefaultClientResponse")
5153
@Reflection private val DefaultClientResponseFieldResponse = DefaultClientResponseClass.getDeclaredField("response").also { it.isAccessible = true }
@@ -249,7 +251,14 @@ class SpringWebClientTransportClient(networkClientManager: NetworkClientManager)
249251
}
250252
} catch (e: Throwable) {
251253
log.w(e) { "Encountered error during HTTP call via WebClient" }
252-
out.errorMessage = e.message
254+
val errorMessage = if (e is WebClientRequestException && e.cause is NoSuchFileException) {
255+
"File not found: ${e.cause?.message}"
256+
} else if (e is NoSuchFileException) {
257+
"File not found: ${e.message}"
258+
} else {
259+
e.message
260+
}
261+
out.errorMessage = errorMessage
253262
out.isError = true
254263
} finally {
255264
out.endAt = KInstant.now()

0 commit comments

Comments
 (0)