{"record":{"id":"8dd2b215b54f70d9","repo":"prestodb/presto","slug":"e-getmessage-8dd2b2","errorCode":null,"errorMessage":"${e.getMessage()}","messagePattern":"\\$\\{e\\.getMessage\\(\\)\\}","errorType":"http","errorClass":"WebApplicationException","httpStatus":502,"severity":"error","filePath":"presto-proxy/src/main/java/com/facebook/presto/proxy/ProxyResource.java","lineNumber":286,"sourceCode":"    private void setupXForwardedFor(HttpServletRequest servletRequest, Request.Builder requestBuilder)\n    {\n        StringBuilder xForwardedFor = new StringBuilder();\n        if (servletRequest.getHeader(X_FORWARDED_FOR) != null) {\n            xForwardedFor.append(servletRequest.getHeader(X_FORWARDED_FOR) + \",\");\n        }\n        xForwardedFor.append(servletRequest.getRemoteAddr());\n        requestBuilder.addHeader(X_FORWARDED_FOR, xForwardedFor.toString());\n    }\n\n    private static <T> T handleProxyException(Request request, ProxyException e)\n    {\n        log.warn(e, \"Proxy request failed: %s %s\", request.getMethod(), request.getUri());\n        throw badRequest(BAD_GATEWAY, e.getMessage());\n    }\n\n    private static WebApplicationException badRequest(Status status, String message)\n    {\n        throw new WebApplicationException(\n                Response.status(status)\n                        .type(TEXT_PLAIN_TYPE)\n                        .entity(message)\n                        .build());\n    }\n\n    private static boolean isPrestoHeader(String name)\n    {\n        return name.toLowerCase(ENGLISH).startsWith(\"x-presto-\");\n    }\n\n    private static Response responseWithHeaders(ResponseBuilder builder, ProxyResponse response)\n    {\n        response.getHeaders().forEach((headerName, value) -> {\n            String name = headerName.toString();\n            if (isPrestoHeader(name) || name.equalsIgnoreCase(SET_COOKIE)) {\n                builder.header(name, value);\n            }","sourceCodeStart":268,"sourceCodeEnd":304,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-proxy/src/main/java/com/facebook/presto/proxy/ProxyResource.java#L268-L304","documentation":"badRequest wraps any message into an HTTP response (here BAD_GATEWAY 502) thrown as a WebApplicationException from the Presto proxy resource. The proxy re-throws an upstream failure's getMessage() verbatim as a plain-text response body. It indicates the proxy's request to the backend Presto server failed.","triggerScenarios":"handleProxyException catches a failure while forwarding the HTTP request to the remote Presto server (getNext, cancelQuery, or bearer-token setup failed) and calls badRequest(BAD_GATEWAY, e.getMessage()).","commonSituations":"Backend Presto coordinator down or restarting; network/timeout between proxy and coordinator; TLS or auth (bearer token) handshake failure; backend returning garbage connection errors.","solutions":["Check that the upstream Presto coordinator address the proxy forwards to is reachable (curl it directly).","Inspect the proxy logs for the underlying 'Proxy request failed' warning with the full stack trace.","Verify network/DNS/firewall and any proxy-to-backend authentication configuration.","Retry the query; if persistent, fix backend health or connection pooling/timeouts."],"exampleFix":"// before: raw message leaks internals\ncatch (Exception e) { throw badRequest(BAD_GATEWAY, e.getMessage()); }\n// after: log full cause, return sanitized body\nlog.warn(e, \"Proxy request failed\"); throw badRequest(BAD_GATEWAY, \"Upstream Presto server unavailable\");","handlingStrategy":"try-catch","validationCode":"// before calling the proxy, check backend health\nconst res = await fetch(backendUri + \"/v1/info\");\nif (!res.ok) throw new Error(\"Presto coordinator unavailable: \" + res.status);","typeGuard":null,"tryCatchPattern":"try {\n  const out = await proxyFetch(uri, opts);\n} catch (e) {\n  if (e.status === 502) {\n    // inspect e.message (upstream cause); retry or surface backend-down\n    log.warn(\"Upstream Presto failed:\", e.message);\n  } else throw e;\n}","preventionTips":["Health-check the backend coordinator before routing traffic through the proxy","Set sensible client timeouts shorter than backend timeouts","Monitor proxy logs for 'Proxy request failed' to catch backend degradation early","Use connection pooling with keep-alive to avoid stale-connection resets"],"tags":["http","proxy","bad-gateway","network"],"backgroundTag":"bad-gateway-upstream-failure","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"}