* @param resp
* The response to complete.
*/
private void handleError(String error, Response resp) {
if (error != null && error.length() > 0) {
ChallengeRequest cr = new ChallengeRequest(
ChallengeScheme.HTTP_OAUTH, "oauth"); // TODO set
// realm
Series<Parameter> parameters = new Form();
parameters.add("error", error);
OAuthError code = OAuthError.valueOf(error);
switch (code) {
case INVALID_REQUEST:
// TODO report bug in Restlet and verify, can not handle
// space char.
// parameters.add("error_description",
// "The request is missing a required parameter.");
resp.setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
break;
case INVALID_TOKEN:
case EXPIRED_TOKEN:
// parameters.add("error_description",
// "The access token provided is invalid.");
resp.setStatus(Status.CLIENT_ERROR_UNAUTHORIZED);
break;
case INSUFFICIENT_SCOPE:
// parameters.add("error_description",
// "The request requires higher privileges than provided "
// +"by the access token.");
resp.setStatus(Status.CLIENT_ERROR_FORBIDDEN);
break;
}
// parameters.add("error_uri",authorizeRef.toString());
cr.setParameters(parameters);
resp.getChallengeRequests().add(cr);
}
}