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

Improved Error Handling

Open agraebe opened this issue 9 years ago • 0 comments

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.

agraebe avatar Jun 26 '16 20:06 agraebe