Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
zari786 opened this issue Sep 9, 2022 · 0 comments
Open

Comments

@zari786
Copy link

zari786 commented Sep 9, 2022

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

@zari786 zari786 changed the title How to parse raw result to error response in simple get request How to parse raw string result to error response in simple get request Sep 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant