Skip to content

fix(server): return 502 instead of passing through upstream 401 - #9231

Merged
klesh merged 2 commits into
apache:mainfrom
abstrask:fix-upstream-401-passthrough
Oct 18, 2026
Merged

klesh merged 2 commits into
apache:mainfrom
abstrask:fix-upstream-401-passthrough

Conversation

@abstrask

@abstrask abstrask commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

shared.ApiOutputError (and its siblings) and the plugin handler wrapper in router.go pass an upstream service's 401 through as DevLake's own HTTP 401. Config UI treats any 401 as an expired DevLake session and redirects to /login.

For example, a GitHub App token request rejected by GitHub during POST /blueprints/:id/trigger sends the user to the login page (which, with AUTH_ENABLED unset, shows "Single Sign-On is not configured").

DevLake's own session and API key 401s are written directly by the auth middleware and never go through these paths, so this maps an upstream 401 to 502 Bad Gateway there. All other status codes are unchanged.

With that in place, the plugin connection test exemption added to config-ui/src/utils/request.ts in #9159 is no longer needed, so the second commit removes it.

Note: this changes the API status code from 401 to 502 for any endpoint that surfaces an upstream 401, including plugin connection tests.

Does this close any open issues?

Part of #9220 (the 401 passthrough part only).

@abstrask

abstrask commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor Author

If you'd prefer a smaller UI-only change instead, following the approach from #9159, this would also fix the trigger case:

+// Blueprint triggers can return 401 from a remote (e.g. GitHub App token request), not a DevLake session expiry.
+const isBlueprintTrigger = (url?: string) => !!url && /\/blueprints\/[^/]+\/trigger\/?$/.test(url);
@@
-      !isPluginConnectionTest(requestUrl)
+      !isPluginConnectionTest(requestUrl) &&
+      !isBlueprintTrigger(requestUrl)

It only covers that one endpoint, though. Other endpoints surfacing an upstream 401 would still redirect to /login. Happy to switch to this if you prefer.

@klesh klesh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
Thanks for your contribution.

@klesh
klesh merged commit ee0079a into apache:main Oct 18, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants