protected void requiresAuthorization() { if (!isAuthorized) { throw new NotAuthorizedException("yahoo", "app has not been authorized"); } }
@Test public void invalidToken() 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.UNAUTHORIZED).body(jsonResource("error_invalid_token")).contentType(MediaType.APPLICATION_JSON)); linkedIn.profileOperations().getUserProfile(); fail(); } catch (NotAuthorizedException e) { assertEquals("Invalid access token.", e.getMessage()); } }
throw new NotAuthorizedException("twitter", response.getStatusText()); } else if (errorText.equals("Could not authenticate you.")) { throw new MissingAuthorizationException("twitter"); throw new InvalidAuthorizationException("twitter", errorText); } else { throw new NotAuthorizedException("twitter", errorText);
throw new NotAuthorizedException("twitter", response.getStatusText()); } else if (errorText.equals("Could not authenticate you.")) { throw new MissingAuthorizationException("twitter"); throw new InvalidAuthorizationException("twitter", errorText); } else { throw new NotAuthorizedException("twitter", errorText);
@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); }
@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); }