-
-
Save yccheok/60da3889df9b920e1ad3703cbdd0c39d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Current code | |
| public static ErrorResponse getErrorResponse (Response<?> response) { | |
| final Gson gson = new Gson(); | |
| try { | |
| String json = response.errorBody().string(); | |
| return gson.fromJson(json, ErrorResponse.class); | |
| } catch (Exception e) { | |
| android.util.Log.e(TAG, "", e); | |
| } | |
| return null; | |
| } | |
| // Not sure this is better, so that caller need not perform null checking. | |
| public static ErrorResponse getErrorResponse (Response<?> response) { | |
| final Gson gson = new Gson(); | |
| ErrorResponse errorResponse; | |
| try { | |
| String json = response.errorBody().string(); | |
| errorResponse = gson.fromJson(json, ErrorResponse.class); | |
| } catch (Exception e) { | |
| android.util.Log.e(TAG, "", e); | |
| } | |
| if (errorResponse == null) { | |
| return new ErrorResponse(-1, ""); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment