Skip to content

Commit

Permalink
Add status code in ApiResult object (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
pietrini authored Nov 6, 2020
1 parent 5720c85 commit ed8495c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ sealed class ApiResult<out R> {
var method: String? = null
internal set

var code: Int = 0
internal set

@JsonClass(generateAdapter = true)
data class Success<out T> internal constructor(
val data: T,
Expand Down
8 changes: 6 additions & 2 deletions amadeus-android/src/main/java/com/amadeus/android/BaseApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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() ?: "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit ed8495c

Please sign in to comment.