private BellaDatiRuntimeException buildException(int code, byte[] content, boolean hasToken) {
		try {
			HttpParameters oauthParams = OAuth.decodeForm(new ByteArrayInputStream(content));
			if (oauthParams.containsKey("oauth_problem")) {
				String problem = oauthParams.getFirst("oauth_problem");
				if ("missing_consumer".equals(problem) || "invalid_consumer".equals(problem)) {
					return new AuthorizationException(Reason.CONSUMER_KEY_UNKNOWN);
				} else if ("invalid_signature".equals(problem) || "signature_invalid".equals(problem)) {
					return new AuthorizationException(hasToken ? Reason.TOKEN_INVALID : Reason.CONSUMER_SECRET_INVALID);
				} else if ("domain_expired".equals(problem)) {
					return new AuthorizationException(Reason.DOMAIN_EXPIRED);
				} else if ("missing_token".equals(problem) || "invalid_token".equals(problem)) {
					return new AuthorizationException(Reason.TOKEN_INVALID);
				} else if ("unauthorized_token".equals(problem)) {
					return new AuthorizationException(Reason.TOKEN_UNAUTHORIZED);
				} else if ("token_expired".equals(problem)) {
					return new AuthorizationException(Reason.TOKEN_EXPIRED);
				} else if ("x_auth_disabled".equals(problem)) {
					return new AuthorizationException(Reason.X_AUTH_DISABLED);
				} else if ("piccolo_not_enabled".equals(problem)) {
					return new AuthorizationException(Reason.BD_MOBILE_DISABLED);
				} else if ("missing_username".equals(problem) || "missing_password".equals(problem)
					|| "invalid_credentials".equals(problem) || "permission_denied".equals(problem)) {
					return new AuthorizationException(Reason.USER_CREDENTIALS_INVALID);
				} else if ("account_locked".equals(problem) || "user_not_active".equals(problem)) {
					return new AuthorizationException(Reason.USER_ACCOUNT_LOCKED);
				} else if ("domain_restricted".equals(problem)) {
					return new AuthorizationException(Reason.USER_DOMAIN_MISMATCH);
				} else if ("timestamp_refused".equals(problem)) {
					String acceptable = oauthParams.getFirst("oauth_acceptable_timestamps");
					if (acceptable != null && acceptable.contains("-")) {
						return new InvalidTimestampException(Long.parseLong(acceptable.split("-")[0]),
							Long.parseLong(acceptable.split("-")[1]));
					}
				}
				return new AuthorizationException(Reason.OTHER, problem);
			}
			return new UnexpectedResponseException(code, new String(content));
		} catch (IOException e) {
			throw new UnexpectedResponseException(code, new String(content), e);
		}

	}
private BellaDatiRuntimeException buildException ( int code , byte [ ] content , boolean hasToken ) { try { HttpParameters oauthParams = OAuth . decodeForm ( new ByteArrayInputStream ( content ) ) ; if ( oauthParams . containsKey ( "oauth_problem" ) ) { String problem = oauthParams . getFirst ( "oauth_problem" ) ; if ( "missing_consumer" . equals ( problem ) || "invalid_consumer" . equals ( problem ) ) { return new AuthorizationException ( Reason . CONSUMER_KEY_UNKNOWN ) ; } else if ( "invalid_signature" . equals ( problem ) || "signature_invalid" . equals ( problem ) ) { return new AuthorizationException ( hasToken ? Reason . TOKEN_INVALID : Reason . CONSUMER_SECRET_INVALID ) ; } else if ( "domain_expired" . equals ( problem ) ) { return new AuthorizationException ( Reason . DOMAIN_EXPIRED ) ; } else if ( "missing_token" . equals ( problem ) || "invalid_token" . equals ( problem ) ) { return new AuthorizationException ( Reason . TOKEN_INVALID ) ; } else if ( "unauthorized_token" . equals ( problem ) ) { return new AuthorizationException ( Reason . TOKEN_UNAUTHORIZED ) ; } else if ( "token_expired" . equals ( problem ) ) { return new AuthorizationException ( Reason . TOKEN_EXPIRED ) ; } else if ( "x_auth_disabled" . equals ( problem ) ) { return new AuthorizationException ( Reason . X_AUTH_DISABLED ) ; } else if ( "piccolo_not_enabled" . equals ( problem ) ) { return new AuthorizationException ( Reason . BD_MOBILE_DISABLED ) ; } else if ( "missing_username" . equals ( problem ) || "missing_password" . equals ( problem ) || "invalid_credentials" . equals ( problem ) || "permission_denied" . equals ( problem ) ) { return new AuthorizationException ( Reason . USER_CREDENTIALS_INVALID ) ; } else if ( "account_locked" . equals ( problem ) || "user_not_active" . equals ( problem ) ) { return new AuthorizationException ( Reason . USER_ACCOUNT_LOCKED ) ; } else if ( "domain_restricted" . equals ( problem ) ) { return new AuthorizationException ( Reason . USER_DOMAIN_MISMATCH ) ; } else if ( "timestamp_refused" . equals ( problem ) ) { String acceptable = oauthParams . getFirst ( "oauth_acceptable_timestamps" ) ; if ( acceptable != null && acceptable . contains ( "-" ) ) { return new InvalidTimestampException ( Long . parseLong ( acceptable . split ( "-" ) [ 0 ] ) , Long . parseLong ( acceptable . split ( "-" ) [ 1 ] ) ) ; } } return new AuthorizationException ( Reason . OTHER , problem ) ; } return new UnexpectedResponseException ( code , new String ( content ) ) ; } catch ( IOException e ) { throw new UnexpectedResponseException ( code , new String ( content ) , e ) ; } }
Builds an exception based on the given content, assuming that it has been
returned as an error from the server.

@param code response code returned by the server
@param content content returned by the server
@param hasToken <tt>true</tt> if the request was made using a request or
access token
@return an exception to throw for the given content