private void handleServerErrors(HttpStatus statusCode) throws IOException { if (statusCode == HttpStatus.INTERNAL_SERVER_ERROR) { throw new InternalServerErrorException("twitter", "Something is broken at Twitter. Please see http://dev.twitter.com/pages/support to report the issue."); } else if (statusCode == HttpStatus.BAD_GATEWAY) { throw new ServerDownException("twitter", "Twitter is down or is being upgraded."); } else if (statusCode == HttpStatus.SERVICE_UNAVAILABLE) { throw new ServerOverloadedException("twitter", "Twitter is overloaded with requests. Try again later."); } }
@Test(expected = InternalServerErrorException.class) public void twitterIsBroken() { try { mockServer.expect(requestTo("https://api.twitter.com/1.1/statuses/home_timeline.json?count=20&include_entities=true")) .andExpect(method(GET)) .andRespond(withServerError().body("Non-JSON body").contentType(APPLICATION_JSON)); twitter.timelineOperations().getHomeTimeline(); } catch (InternalServerErrorException e) { assertEquals("Something is broken at Twitter. Please see http://dev.twitter.com/pages/support to report the issue.", e.getMessage()); throw e; } }
private void handleServerErrors(HttpStatus statusCode) throws IOException { if (statusCode == HttpStatus.INTERNAL_SERVER_ERROR) { throw new InternalServerErrorException("twitter", "Something is broken at Twitter. Please see http://dev.twitter.com/pages/support to report the issue."); } else if (statusCode == HttpStatus.BAD_GATEWAY) { throw new ServerDownException("twitter", "Twitter is down or is being upgraded."); } else if (statusCode == HttpStatus.SERVICE_UNAVAILABLE) { throw new ServerOverloadedException("twitter", "Twitter is overloaded with requests. Try again later."); } }
private void handleServerErrors(HttpStatus statusCode) throws IOException { if (statusCode == HttpStatus.INTERNAL_SERVER_ERROR) { throw new InternalServerErrorException( "Something is broken at Weibo."); } else if (statusCode == HttpStatus.BAD_GATEWAY) { throw new ServerDownException("Weibo is down or is being upgraded."); } else if (statusCode == HttpStatus.SERVICE_UNAVAILABLE) { throw new ServerOverloadedException( "Weibo is overloaded with requests. Try again later."); } }
private void handleSalesforceError(HttpStatus statusCode, Map<String, Object> errorDetails) { if (statusCode.equals(HttpStatus.NOT_FOUND)) { throw new ResourceNotFoundException(SalesforceServiceProvider.ID, extractErrorMessage(errorDetails)); } else if (statusCode.equals(HttpStatus.SERVICE_UNAVAILABLE)) { throw new RateLimitExceededException(SalesforceServiceProvider.ID); } else if (statusCode.equals(HttpStatus.INTERNAL_SERVER_ERROR)) { throw new InternalServerErrorException(SalesforceServiceProvider.ID, errorDetails == null ? "Contact Salesforce administrator." : extractErrorMessage(errorDetails)); } else if (statusCode.equals(HttpStatus.BAD_REQUEST) || statusCode.equals(HttpStatus.MULTIPLE_CHOICES)) { throw new SalesforceRequestException(SalesforceServiceProvider.ID, errorDetails); } else if (statusCode.equals(HttpStatus.UNAUTHORIZED)) { throw new InvalidAuthorizationException(SalesforceServiceProvider.ID, extractErrorMessage(errorDetails)); } else if (statusCode.equals(HttpStatus.FORBIDDEN)) { if(errorDetails.get(ERROR_CODE).equals(BAD_OAUTH_TOKEN)) { //This is recoverable by refreshing oauth tokens. throw new InsufficientPermissionException(extractErrorMessage(errorDetails)); } else { throw new InsufficientPermissionException(extractErrorMessage(errorDetails)); } } }