@Test public void parseError_whenUnknownError_shouldReturnKnownError() { String body = "{\"error\":\"This is not a supported Error\",\"random\":\"random field\"}"; ApiError apiError = ErrorParser.parseError(body, 416, "ThisWasTheHttpMessage"); assertError(apiError.getClientErrors(), null, 416, "Unknown Error"); }
@Nullable public static ApiError parseError(@Nonnull Response<?> response) { if (response.isSuccessful()) { return null; } try { return parseError(response.errorBody().string(), response.code(), response.message()); } catch (IOException e) { return new ApiError(null, response.code(), "Unknown Error"); } }
ErrorParser { @Nullable public static ApiError parseError(@Nonnull Response<?> response) { if (response.isSuccessful()) { return null; } try { return parseError(response.errorBody().string(), response.code(), response.message()); } catch (IOException e) { return new ApiError(null, response.code(), "Unknown Error"); } } }
ErrorParser { @Nullable public static ApiError parseError(@Nonnull Response<?> response) { if (response.isSuccessful()) { return null; } try { return parseError(response.errorBody().string(), response.code(), response.message()); } catch (IOException e) { return new ApiError(null, response.code(), "Unknown Error"); } }  }
ErrorParser { @Nullable public static ApiError parseError(@Nonnull Response<?> response) { if (response.isSuccessful()) { return null; } try { return parseError(response.errorBody().string(), response.code(), response.message()); } catch (IOException e) { return new ApiError(null, response.code(), "Unknown Error"); } }  @Nullable static ApiError parseError(@Nonnull Response<?> response); @Nonnull static ApiError parseError(@Nullable String errorBody, int statusCode, @Nullable String message); }
ErrorParser { @Nullable public static ApiError parseError(@Nonnull Response<?> response) { if (response.isSuccessful()) { return null; } try { return parseError(response.errorBody().string(), response.code(), response.message()); } catch (IOException e) { return new ApiError(null, response.code(), "Unknown Error"); } }  @Nullable static ApiError parseError(@Nonnull Response<?> response); @Nonnull static ApiError parseError(@Nullable String errorBody, int statusCode, @Nullable String message);  }