Skip to content

Commit 69c77b6

Browse files
authored
Update send() to forward all errors (#22)
1 parent b2f5e55 commit 69c77b6

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

library/src/main/kotlin/build/buf/connect/http/HTTPClientInterface.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,12 @@ class Stream(
5656
if (isClosed()) {
5757
return Result.failure(IllegalStateException("cannot send. underlying stream is closed"))
5858
}
59-
onSend(buffer)
60-
return Result.success(Unit)
59+
return try {
60+
onSend(buffer)
61+
Result.success(Unit)
62+
} catch (e: Throwable) {
63+
Result.failure(e)
64+
}
6165
}
6266

6367
fun close() {

okhttp/src/main/kotlin/build/buf/connect/okhttp/OkHttpStream.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ internal class PipeDuplexRequestBody(
193193
bufferedSink.writeAll(buffer)
194194
bufferedSink.flush()
195195
}
196-
} catch (e: Throwable) {
196+
} finally {
197197
close()
198198
}
199199
}

0 commit comments

Comments
 (0)