@@ -5,6 +5,7 @@ import failchat.exception.UnexpectedResponseException
55import okhttp3.Call
66import okhttp3.Callback
77import okhttp3.MediaType
8+ import okhttp3.MediaType.Companion.toMediaTypeOrNull
89import okhttp3.RequestBody
910import okhttp3.Response
1011import okhttp3.ResponseBody
@@ -14,8 +15,8 @@ import kotlin.coroutines.resume
1415import kotlin.coroutines.resumeWithException
1516import kotlin.coroutines.suspendCoroutine
1617
17- val jsonMediaType: MediaType = MediaType .parse( " application/json" )!!
18- val textMediaType: MediaType = MediaType .parse( " text/plain" )!!
18+ val jsonMediaType: MediaType = " application/json" .toMediaTypeOrNull( )!!
19+ val textMediaType: MediaType = " text/plain" .toMediaTypeOrNull( )!!
1920val emptyBody: RequestBody = RequestBody .create(textMediaType, " " )
2021
2122fun Call.toFuture (): CompletableFuture <Response > {
@@ -47,11 +48,11 @@ suspend fun Call.await(): Response {
4748}
4849
4950fun Response.getBodyIfStatusIs (expectedStatus : Int ): Response {
50- if (this .code() != expectedStatus) {
51- throw UnexpectedResponseCodeException (this .code() , request() .url() .toString())
51+ if (this .code != expectedStatus) {
52+ throw UnexpectedResponseCodeException (this .code, request.url.toString())
5253 }
5354 return this
5455}
5556
5657val Response .nonNullBody: ResponseBody
57- get() = this .body() ? : throw UnexpectedResponseException (" null body" )
58+ get() = this .body ? : throw UnexpectedResponseException (" null body" )
0 commit comments