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

ERROR 422 - Unknown Error when using loadRideInformation. #174

Open
albertoha94 opened this issue Sep 10, 2019 · 0 comments
Open

ERROR 422 - Unknown Error when using loadRideInformation. #174

albertoha94 opened this issue Sep 10, 2019 · 0 comments

Comments

@albertoha94
Copy link

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

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