@Override protected String parseResponse(HttpURLConnection connection) throws Exception { try { return super.parseResponse(connection); } catch (UnprocessableEntityException e) { throw new BraintreeApiErrorResponse(e.getMessage()); } } }
protected String parseResponse(HttpURLConnection connection) throws Exception { int responseCode = connection.getResponseCode(); boolean gzip = "gzip".equals(connection.getContentEncoding()); switch(responseCode) { case HTTP_OK: case HTTP_CREATED: case HTTP_ACCEPTED: return readStream(connection.getInputStream(), gzip); case HTTP_UNAUTHORIZED: throw new AuthenticationException(readStream(connection.getErrorStream(), gzip)); case HTTP_FORBIDDEN: throw new AuthorizationException(readStream(connection.getErrorStream(), gzip)); case HTTP_BAD_REQUEST: case 422: // HTTP_UNPROCESSABLE_ENTITY throw new UnprocessableEntityException(readStream(connection.getErrorStream(), gzip)); case 426: // HTTP_UPGRADE_REQUIRED throw new UpgradeRequiredException(readStream(connection.getErrorStream(), gzip)); case 429: // HTTP_TOO_MANY_REQUESTS throw new RateLimitException("You are being rate-limited. Please try again in a few minutes."); case HTTP_INTERNAL_ERROR: throw new ServerException(readStream(connection.getErrorStream(), gzip)); case HTTP_UNAVAILABLE: throw new DownForMaintenanceException(readStream(connection.getErrorStream(), gzip)); default: throw new UnexpectedException(readStream(connection.getErrorStream(), gzip)); } }