{"record":{"id":"c37633aa73c3276d","repo":"prestodb/presto","slug":"bad-status-code-from-remote-presto-server-s-s","errorCode":null,"errorMessage":"Bad status code from remote Presto server: %s: %s","messagePattern":"Bad status code from remote Presto server: (.+?): (.+?)","errorType":"exception","errorClass":"ProxyException","httpStatus":502,"severity":"error","filePath":"presto-proxy/src/main/java/com/facebook/presto/proxy/ProxyResponseHandler.java","lineNumber":53,"sourceCode":"        implements ResponseHandler<ProxyResponse, RuntimeException>\n{\n    private static final MediaType MEDIA_TYPE_JSON = MediaType.create(\"application\", \"json\");\n\n    @Override\n    public ProxyResponse handleException(Request request, Exception exception)\n    {\n        throw new ProxyException(\"Request to remote Presto server failed\", exception);\n    }\n\n    @Override\n    public ProxyResponse handle(Request request, Response response)\n    {\n        if (response.getStatusCode() == NO_CONTENT.code()) {\n            return new ProxyResponse(response.getHeaders(), new byte[0]);\n        }\n\n        if (response.getStatusCode() != OK.code()) {\n            throw new ProxyException(format(\"Bad status code from remote Presto server: %s: %s\", response.getStatusCode(), readBody(response)));\n        }\n\n        String contentType = response.getHeader(CONTENT_TYPE);\n        if (contentType == null) {\n            throw new ProxyException(\"No Content-Type set in response from remote Presto server\");\n        }\n        if (!MediaType.parse(contentType).is(MEDIA_TYPE_JSON)) {\n            throw new ProxyException(\"Bad Content-Type from remote Presto server:\" + contentType);\n        }\n\n        try {\n            return new ProxyResponse(response.getHeaders(), toByteArray(response.getInputStream()));\n        }\n        catch (IOException e) {\n            throw new ProxyException(\"Failed reading response from remote Presto server\", e);\n        }\n    }\n","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-proxy/src/main/java/com/facebook/presto/proxy/ProxyResponseHandler.java#L35-L71","documentation":"The proxy expects HTTP 200 (or 204) from the remote Presto server. Any other status is wrapped in a ProxyException with the status code and the response body embedded in the message. It means the backend rejected or failed the request at the HTTP level.","triggerScenarios":"Remote server returned e.g. 401/403 (auth), 404 (wrong URI/path), 500 (internal error), or 503 (unavailable) for a proxied call; the body is included via readBody(response).","commonSituations":"Expired/missing bearer token forwarded to backend; wrong remote server port or context path; backend returning 503 during restart or overload.","solutions":["Read the status code and body in the message to identify the backend's complaint.","Fix authentication if 401/403 (check forwarded credentials/bearer token setup).","Correct the remote server URI/port if 404.","If 500/503, check backend Presto coordinator logs and health."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// check the endpoint returns 200 before issuing real work\nconst probe = await fetch(backendUri + path, { method: \"HEAD\", headers });\nif (![200, 204].includes(probe.status)) throw new Error(\"Backend status \" + probe.status);","typeGuard":null,"tryCatchPattern":"try {\n  return await proxyCall(req);\n} catch (e) {\n  const m = /Bad status code .*?: (\\d+):/.exec(String(e.message));\n  if (m) {\n    const status = Number(m[1]);\n    if (status === 401 || status === 403) refreshCredentials();\n    else if (status === 503) scheduleRetry();\n  }\n  throw e;\n}","preventionTips":["Keep forwarded auth tokens fresh and valid for the backend","Verify remote server URI/port/context path in proxy config","Alert on backend 5xx rates","Read the response body embedded in the message for the backend's own error detail"],"tags":["http","status-code","proxy","remote-server"],"backgroundTag":"unexpected-http-status","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}