public static ClientRegistrationErrorResponse parse(final HTTPResponse httpResponse)
throws ParseException {
httpResponse.ensureStatusCodeNotOK();
ErrorObject error;
String wwwAuth = httpResponse.getWWWAuthenticate();
if (StringUtils.isNotBlank(wwwAuth)) {
error = BearerTokenError.parse(wwwAuth);
} else {
String code = null;
String description = null;
if (CommonContentTypes.APPLICATION_JSON.match(httpResponse.getContentType())) {
JSONObject jsonObject = httpResponse.getContentAsJSONObject();
code = JSONObjectUtils.getString(jsonObject, "error");
if (jsonObject.containsKey("error_description"))
description = JSONObjectUtils.getString(jsonObject, "error_description");
}
error = new ErrorObject(code, description, httpResponse.getStatusCode());
}
return new ClientRegistrationErrorResponse(error);
}