uber / rides-java-sdk

Uber Rides Java SDK (beta)
https://developer.uber.com/docs
MIT License
105 stars 56 forks source link

Improved Error Handling #19

Open agraebe opened 8 years ago

agraebe commented 8 years ago

Right now, the retrofit2 lib returns a response that could have failed, for instance by mixing up server_token and OAuth authentication methods. Getting an understandable error is not as easy as it could be:

Response<UserProfile> response = service.getUserProfile().execute();
        if (response.isSuccessful()) {
            // Success
            UserProfile profile = response.body();
            System.out.println(profile.toString());
        } else {
            // Failure
            ApiError error = ErrorParser.parseError(response);
            List<ClientError> errors = error.getClientErrors();
            // show error code and message
            for (int i = 0; i < errors.size(); i++) {
                System.out.println(error.getClientErrors().get(i).getStatus() + " "
                        + error.getClientErrors().get(i).getCode() + ": " + error.getClientErrors().get(i).getTitle());
            }
        }

Every user would need to loop through the whole error list. A simple method would be helpful.