Skip to content

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

@zari786

Description

@zari786

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions