SonarSource/sonarqube · error · IllegalStateException
Fail to execute request '%s'. HTTP code: %s, response: %s
Error message
Fail to execute request '%s'. HTTP code: %s, response: %s
What it means
OAuthRestClient.executeRequest performs a signed GET against an external identity-provider API (e.g. GitHub/GitLab/Bitbucket) using ScribeJava. If the HTTP response status is not 2xx, SonarQube aborts and throws this message embedding the URL, status code, and response body. It indicates the upstream ALM API rejected the request — bad/expired token, wrong URL, or provider-side error.
Source
Thrown at server/sonar-auth-common/src/main/java/org/sonar/auth/OAuthRestClient.java:54
import static java.lang.String.format;
public class OAuthRestClient {
private static final int DEFAULT_PAGE_SIZE = 100;
private static final Pattern NEXT_LINK_PATTERN = Pattern.compile("<([^<]+)>; rel=\"next\"");
private OAuthRestClient() {
// Only static method
}
public static Response executeRequest(String requestUrl, OAuth20Service scribe, OAuth2AccessToken accessToken) throws IOException {
OAuthRequest request = new OAuthRequest(Verb.GET, requestUrl);
scribe.signRequest(accessToken, request);
try {
Response response = scribe.execute(request);
if (!response.isSuccessful()) {
throw unexpectedResponseCode(requestUrl, response);
}
return response;
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IllegalStateException(e);
} catch (ExecutionException e) {
throw new IllegalStateException(e);
}
}
public static <E> List<E> executePaginatedRequest(String request, OAuth20Service scribe, OAuth2AccessToken accessToken, Function<String, List<E>> function) {
List<E> result = new ArrayList<>();
readPage(result, scribe, accessToken, addPerPageQueryParameter(request, DEFAULT_PAGE_SIZE), function);
return result;
}
public static String addPerPageQueryParameter(String request, int pageSize) {
String separator = request.contains("?") ? "&" : "?";View on GitHub (pinned to 184c821202)
Solutions
- Check the URL, status code and body in the message to identify the provider-side cause.
- Regenerate/re-authorize the OAuth app or token in SonarQube ALM settings (Administration > DevOps Platform) if the response is 401/403.
- Verify the ALM base URL and that the account has the required scopes (e.g. GitHub: repo, read:org).
- Check provider status/rate limits for 429/5xx and retry after the issue clears.
- Confirm network/proxy configuration allows SonarQube to reach the provider.
Example fix
// before
settings.put("alm.github.url", "https://github.example.internal/api"); // wrong API path
// after
settings.put("alm.github.url", "https://github.example.internal"); // correct base URL + re-authorized token Defensive patterns
Strategy: retry
Validate before calling
// Java: check token and URL before calling
if (accessToken == null || accessToken.getAccessToken().isEmpty()) throw new IllegalArgumentException("missing access token");
if (!requestUrl.startsWith("https://")) throw new IllegalArgumentException("ALM URL must be https"); Type guard
boolean isUsableToken(OAuth2AccessToken t) { return t != null && t.getAccessToken() != null && !t.getAccessToken().isEmpty(); } Try / catch
try {
Response r = OAuthRestClient.executeRequest(url, scribe, token);
} catch (IOException e) {
if (e.getMessage().contains("HTTP code: 40") ) refreshTokenAndRetry();
else if (e.getMessage().contains("HTTP code: 429") || e.getMessage().contains("HTTP code: 5")) backoffAndRetry();
else throw new AlmConfigurationException(e);
} Prevention
- Re-authorize ALM connections whenever credentials or scopes change
- Monitor provider status pages and rate limits
- Log the full response body for diagnosis (it is embedded in the message)
- Validate ALM base URLs right after configuration changes
When it happens
Trigger: Calling readPage (pagination fetch of users/groups from the ALM) when the provider returns 401/403/404/5xx: expired or revoked OAuth access token, insufficient token scopes, wrong API base URL configured, or the provider being temporarily down (502/503).
Common situations: DevOps rotated GitHub App credentials or revoked tokens; ALM base URL points to an on-prem instance with a different API path; token scopes narrowed (missing repo/read:org); corporate proxy returning 403; rate limiting from the provider.
Understand the failure class
Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.
Related errors
- Fail to download: %s
- SonarQube was not able to retrieve resources from external s
- Unable to contact Bitbucket Cloud servers
- Failed to create GitHub's user access token. GitHub returned
- Could not validate GitLab write permission. Got an unexpecte
AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09).
Data as JSON: /api/errors/1d552bfbe640fe09.
Report an issue: GitHub.