Skip to content

Commit bccddc2

Browse files
authored
Fix validateResponse method (#22)
* fix validateResponse method Signed-off-by: Anatoli Kalbasin <[email protected]>
1 parent 3864d83 commit bccddc2

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/main/kotlin/org/zowe/kotlinsdk/ResponseValidator.kt

+7-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ import retrofit2.Response
1313
*/
1414
fun validateResponse(response: Response<*>?, defaultMessage: String = "") {
1515
if (response?.isSuccessful != true) {
16-
if (response?.errorBody()?.string().isNullOrBlank()) {
17-
throw Exception("HTTP code = ${response?.code()}; Message: ${response?.message()}")
18-
} else {
19-
throw Exception("${if (defaultMessage.isBlank()) "" else "$defaultMessage. "}${response?.errorBody()?.string()}")
16+
val errorBody = response?.errorBody()?.string()
17+
errorBody?.let {
18+
if (errorBody.isBlank()) {
19+
throw Exception("HTTP code = ${response.code()}; Message: ${response.message()}")
20+
} else {
21+
throw Exception("${if (defaultMessage.isBlank()) "" else "$defaultMessage. "}${errorBody}")
22+
}
2023
}
2124
}
2225
}

0 commit comments

Comments
 (0)