bsimmons
08/18/2021, 11:51 AM/** Convert promise with HTTP 500 response to failed promise. */
fun Promise<Response>.handleErrorCodes(): Promise<Response> = then { response ->
if(response.ok) response
else response.text().then { body ->
throw RuntimeException("${response.status}: $body")
}
}.then { it as Response }
thana
08/18/2021, 1:18 PMPromise<Promise<T>>
automatically into Promise<T>
. As Kotlin cannot do this, there is a extension function unwrapping it for you.
but still you'd have to write then {it}
thana
08/18/2021, 1:18 PMturansky
08/18/2021, 2:10 PMbsimmons
08/18/2021, 2:44 PM