smartcar / java-sdk

Java client SDK for the Smartcar API.
https://smartcar.github.io/java-sdk
MIT License
20 stars 20 forks source link

Feat: Vehicle State Errors #53

Closed adolfoportilla closed 5 years ago

codecov[bot] commented 5 years ago

Codecov Report

Merging #53 into master will decrease coverage by 7.2%. The diff coverage is 4.54%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master      #53      +/-   ##
============================================
- Coverage     60.67%   53.47%   -7.21%     
+ Complexity       61       51      -10     
============================================
  Files            17       17              
  Lines           417      389      -28     
  Branches         18       15       -3     
============================================
- Hits            253      208      -45     
- Misses          155      172      +17     
  Partials          9        9
Flag Coverage Δ Complexity Δ
#integration 51.67% <4.54%> (+3.22%) 51 <0> (ø) :arrow_down:
#test 6.68% <0%> (-10.11%) 5 <0> (-10)
Impacted Files Coverage Δ Complexity Δ
src/main/java/com/smartcar/sdk/Vehicle.java 79.62% <ø> (ø) 12 <0> (ø) :arrow_down:
src/main/java/com/smartcar/sdk/ApiClient.java 79.41% <0%> (ø) 6 <0> (ø) :arrow_down:
.../main/java/com/smartcar/sdk/SmartcarException.java 0% <0%> (-91.67%) 0 <0> (-10)
src/main/java/com/smartcar/sdk/AuthClient.java 76.19% <100%> (+0.99%) 11 <0> (ø) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 2a5ccb1...c82a8df. Read the comment docs.

johnmryan commented 5 years ago

Just a quick thought based on the discussion we had earlier, can punt on it for now since it's probably out of scope.

public class ResponseHandler {
    public static handleErrorResponse(final Response response) throws IOException {
        JsonObject body = gson.fromJson(response.body().string(), JsonObject.class);
        String code = "";
        JsonElement codeElement = body.get("code");
        if (codeElement != null) {
            code = codeElement.getAsString();
        }
        String message = body.get("message").getAsString();
        String error = body.get("error").getAsString();
        Integer statusCode = response.code();
        return new ResponseError(statusCode, error, message, code);
    }
}

public class ResponseError {
    public ResponseError(int statusCode, String error, String message, int code) {
        ...
    }
}
if (!response.isSuccessful()) {
    ResponseError error = ResponseHandler.handleErrorResponse(response);
    throw new SmartcarException(error.getMessage(), error.getCode(), ...);
}