Skip to content

Commit a4998cf

Browse files
committed
Added Response constructor overload
1 parent d72ac38 commit a4998cf

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/main/kotlin/at/bitfire/dav4jvm/exception/DavException.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,21 @@ open class DavException @JvmOverloads constructor(
7676
var errors: List<Error> = listOf()
7777
private set
7878

79+
/**
80+
* Initializes the [DavException] and populates [request], [requestBody], [response], [responseBody] and [errors] with the contents of [httpResponse].
81+
*
82+
* The whole response body may be loaded, so this function should be called in blocking-sensitive contexts.
83+
*/
84+
constructor(message: String, httpResponse: Response?, ex: Throwable? = null): this(message, ex) {
85+
populateHttpResponse(httpResponse)
86+
}
7987

80-
fun populateHttpResponse(httpResponse: Response?): DavException {
88+
/**
89+
* Fills [request], [requestBody], [response], [responseBody] and [errors] according to the given [httpResponse].
90+
*
91+
* The whole response body may be loaded, so this function should be called in blocking-sensitive contexts.
92+
*/
93+
private fun populateHttpResponse(httpResponse: Response?): DavException {
8194
if (httpResponse != null) {
8295
response = httpResponse.toString()
8396

src/main/kotlin/at/bitfire/dav4jvm/exception/HttpException.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ open class HttpException: DavException {
2020
var code: Int
2121

2222
constructor(response: Response): super(
23-
"HTTP ${response.code} ${response.message}"
23+
"HTTP ${response.code} ${response.message}",
24+
httpResponse = response
2425
) {
2526
code = response.code
26-
populateHttpResponse(response)
2727
}
2828

2929
constructor(code: Int, message: String?): super("HTTP $code $message") {

0 commit comments

Comments
 (0)