private String getRequiredScope(ApiException apiException) { return apiException instanceof InsufficientPermissionException ? ((InsufficientPermissionException) apiException).getRequiredPermission() : null; }
@Override public void handleError(ClientHttpResponse response) throws IOException { Map<String, Object> errorDetails = extractErrorDetailsFromResponse(response); String message = (String) errorDetails.get("message"); HttpStatus statusCode = response.getStatusCode(); if (statusCode.equals(HttpStatus.UNAUTHORIZED)) { throw new NotAuthorizedException("linkedIn", message); } else if (statusCode.equals(HttpStatus.FORBIDDEN)) { if (message.contains("Throttle")) { throw new RateLimitExceededException("linkedin"); } else { throw new InsufficientPermissionException("linkedin"); } } else if (statusCode.equals(HttpStatus.NOT_FOUND)) { throw new ResourceNotFoundException("linkedin", message); } handleUncategorizedError(response); }
@Test public void insufficientPermission() throws Exception { try { mockServer.expect(requestTo("https://api.linkedin.com/v1/people/~:(id,first-name,last-name,emailAddress,headline,industry,site-standard-profile-request,public-profile-url,picture-url,summary)?format=json&oauth2_access_token=ACCESS_TOKEN")) .andExpect(method(GET)) .andRespond(withStatus(HttpStatus.FORBIDDEN).body(jsonResource("error_insufficient_permission")).contentType(MediaType.APPLICATION_JSON)); linkedIn.profileOperations().getUserProfile(); fail(); } catch (InsufficientPermissionException e) { assertEquals("Insufficient permission for this operation.", e.getMessage()); } }
@Override public void handleError(ClientHttpResponse response) throws IOException { Map<String, Object> errorDetails = extractErrorDetailsFromResponse(response); String message = (String) errorDetails.get("message"); HttpStatus statusCode = response.getStatusCode(); if (statusCode.equals(HttpStatus.UNAUTHORIZED)) { throw new NotAuthorizedException("linkedIn", message); } else if (statusCode.equals(HttpStatus.FORBIDDEN)) { if (message.contains("Throttle")) { throw new RateLimitExceededException("linkedin"); } else { throw new InsufficientPermissionException("linkedin"); } } else if (statusCode.equals(HttpStatus.NOT_FOUND)) { throw new ResourceNotFoundException("linkedin", message); } handleUncategorizedError(response); }
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)); } } }
throw new RateLimitExceededException(FACEBOOK_PROVIDER_ID); } else if (code == PERMISSION_DENIED || isUserPermissionError(code)) { throw new InsufficientPermissionException(FACEBOOK_PROVIDER_ID); } else if (code == PARAM_SESSION_KEY || code == PARAM_SIGNATURE) { throw new InvalidAuthorizationException(FACEBOOK_PROVIDER_ID, error.getMessage());
throw new RateLimitExceededException(FACEBOOK_PROVIDER_ID); } else if (code == PERMISSION_DENIED || isUserPermissionError(code)) { throw new InsufficientPermissionException(FACEBOOK_PROVIDER_ID); } else if (code == PARAM_SESSION_KEY || code == PARAM_SIGNATURE) { throw new InvalidAuthorizationException(FACEBOOK_PROVIDER_ID, error.getMessage());