diff --git a/amadeus-android/src/main/java/com/amadeus/android/ApiResult.kt b/amadeus-android/src/main/java/com/amadeus/android/ApiResult.kt index 8b9a6463..90e562cd 100644 --- a/amadeus-android/src/main/java/com/amadeus/android/ApiResult.kt +++ b/amadeus-android/src/main/java/com/amadeus/android/ApiResult.kt @@ -12,6 +12,9 @@ sealed class ApiResult { var method: String? = null internal set + var code: Int = 0 + internal set + @JsonClass(generateAdapter = true) data class Success internal constructor( val data: T, diff --git a/amadeus-android/src/main/java/com/amadeus/android/BaseApi.kt b/amadeus-android/src/main/java/com/amadeus/android/BaseApi.kt index 94bd7da2..37dcd484 100644 --- a/amadeus-android/src/main/java/com/amadeus/android/BaseApi.kt +++ b/amadeus-android/src/main/java/com/amadeus/android/BaseApi.kt @@ -24,8 +24,12 @@ open class BaseApi( return withContext(dispatcher) { try { val response = call() - if (response.isSuccessful && response.body() != null) { - response.body()!!.apply { method = response.raw().request.method } + val body = response.body() + if (response.isSuccessful && body != null) { + body.apply { + method = response.raw().request.method + code = response.code() + } } else { moshi.adapter(ApiResult.Error::class.java) .fromJson(response.errorBody()?.string() ?: "") diff --git a/amadeus-android/src/test/java/com/amadeus/android/integration/AmadeusTest.kt b/amadeus-android/src/test/java/com/amadeus/android/integration/AmadeusTest.kt index a1911825..d6f325da 100644 --- a/amadeus-android/src/test/java/com/amadeus/android/integration/AmadeusTest.kt +++ b/amadeus-android/src/test/java/com/amadeus/android/integration/AmadeusTest.kt @@ -56,6 +56,11 @@ class AmadeusTest { assert(amadeus.referenceData.urls.checkinLinks.get("LH").succeeded) } + @Test + fun `Response code is set`() = runBlocking { + assert(amadeus.referenceData.urls.checkinLinks.get("LH").code == 200) + } + @Test fun `Locations Airports`() = runBlocking { assert(