amadeus4dev-examples / amadeus-android

Android (Kotlin) library for the Amadeus Self-Service travel APIs
https://developers.amadeus.com/
MIT License
19 stars 8 forks source link

How to parse raw string result to error response in simple get request #84

Open zari786 opened 2 years ago

zari786 commented 2 years ago

I'm working on hotel booking and I want to show autocomplete cities to the user but I'm stuck on error response when the response is successful it's working fine, but when no data found it throws error and the app crash.

here is a blow code

val apiResponse = amadeus.get("https://test.api.amadeus.com/v1/reference-data/locations/cities?keyword=$keyword")

val type = Types.newParameterizedType(
                List::class.java,
                Location::class.java
            )
            val responseType = Types.newParameterizedTypeWithOwner(
                ApiResult::class.java,
                ApiResult.Success::class.java,
                type
            )

            val locationAdapter =
                amadeus.moshi.adapter<ApiResult.Success<List<Location>>>(resultType)

val cityDetail = locationAdapter.fromJson(apiResponse)

I'm getting error on this line val cityDetail = locationAdapter.fromJson(apiResponse) when user enter invalid location which does not found. I've attached the error along with raw response. Any help will be appreciated.

error