rides-android-sdk icon indicating copy to clipboard operation
rides-android-sdk copied to clipboard

ERROR 422 - Unknown Error when using loadRideInformation.

Open albertoha94 opened this issue 6 years ago • 0 comments
trafficstars

I think this might be a bug since this happened while following the uber example provided for Android. https://developer.uber.com/docs/riders/ride-requests/tutorials/button/android

Library version: 0.10.1

Code:

private fun initUberRideButton(startLocation: Location?, productId: String? = null) {
    val sessionConfiguration = getUberSessionConfiguration()
    UberSdk.initialize(sessionConfiguration)

    val rideParams = getUberRideParams(startLocation, productId)
    val session = ServerTokenSession(sessionConfiguration)
    val callback = getUberCallback()

    buttonUberRideRequest?.setRideParameters(rideParams)
    buttonUberRideRequest?.setSession(session)
    buttonUberRideRequest?.setCallback(callback)
    buttonUberRideRequest?.loadRideInformation()
}


// region Uber getters.

/**
 * Returns callback object for uber request button.
 * @return RideRequestButtonCallback object to use.
 */
private fun getUberCallback(): RideRequestButtonCallback {
    return object : RideRequestButtonCallback {

        override fun onRideInformationLoaded() {
            requireContext().toast("Uber information loaded")
        }

        override fun onError(apiError: ApiError?) {
            apiError?.clientErrors?.forEach {
                Timber.tag(UBER_TAG).e("${it.title} ${it.code} ${it.status} ")
            }
        }

        override fun onError(throwable: Throwable?) {
            Timber.tag(UBER_TAG).e(throwable?.localizedMessage)
        }
    }
}

/**
 * Creates a RideParameters object for Uber API.
 * @param startLocation Current location of the user.
 * @param productId Current id of uber car selected.
 * @return A RideParameters object.
 */
private fun getUberRideParams(startLocation: Location?, productId: String?): RideParameters {
    val builder = if (startLocation.isAtHome()) {
        RideParameters.Builder()
            .setPickupLocation(homeLocation.latitude, homeLocation.longitude, getString(R.string.home), null)
    } else {
        RideParameters.Builder()
            .setPickupLocation(startLocation?.latitude, startLocation?.longitude, getString(R.string.your_location), null)
            .setDropoffLocation(homeLocation.latitude, homeLocation.longitude, getString(R.string.home), null)
    }
    if (!productId.isNullOrEmpty()) {
        builder.setProductId(productId)
    }

    return builder.build()
}

/**
 * Gets the uber configuration used in the app.
 * @return Session Configuration object used by the uber api.
 */
private fun getUberSessionConfiguration(): SessionConfiguration = SessionConfiguration.Builder()
    .setClientId(clientID)
    .setServerToken(serverToken)
    .setEnvironment(SessionConfiguration.Environment.SANDBOX)
    .build()

// endregion`

Error obtained from debug:

0 = {ClientError@10443} code = null status = 422 title = "Unknown Error" shadow$klass = {Class@10339} "class com.uber.sdk.rides.client.error.ClientError" shadow$monitor = -1892382548

Current result: Button stays as ride there with uber and opens the play store. image

Ride request button callback always calls onError(apiError: ApiError?) instead of onRideInformationLoaded()

Expected Behavior: I should see the button with time estimate and price like in the example. image

albertoha94 avatar Sep 10 '19 17:09 albertoha94