Skip to content

Fix auth error handling#24420

Merged
crazywoola merged 1 commit intolanggenius:mainfrom
hyongtao-code:fix-24337
Aug 25, 2025
Merged

Fix auth error handling#24420
crazywoola merged 1 commit intolanggenius:mainfrom
hyongtao-code:fix-24337

Conversation

@hyongtao-code
Copy link
Copy Markdown
Contributor

Fixes #24337

Unauthorized is a subclass of HTTPException -> Exception, so the old code silently swallowed it, causing 401 responses to never reach the client.

Now,

  • Replace except Exception: pass with explicit handling:
  • except Unauthorized: raise → let 401 bubble up correctly
  • except Exception: → log and re-raise unexpected errors

Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

Screenshots

Before After
... ...

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods

`Unauthorized` is a subclass of `Exception`, so the
old code silently swallowed it, causing 401 responses
to never reach the client.

Now,
- Replace `except Exception: pass` with explicit handling:
- `except Unauthorized: raise` → let 401 bubble up correctly
- `except Exception:` → log and re-raise unexpected errors

Signed-off-by: Yongtao Huang <yongtaoh2022@gmail.com>
@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Aug 24, 2025
@asukaminato0721
Copy link
Copy Markdown
Contributor

how about #24427 :P

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Aug 25, 2025
@crazywoola crazywoola merged commit 9a18911 into langgenius:main Aug 25, 2025
7 checks passed
@hyongtao-code hyongtao-code deleted the fix-24337 branch August 25, 2025 01:44
Eric-Guo added a commit to Eric-Guo/dify that referenced this pull request Aug 25, 2025
@lyzno1 lyzno1 mentioned this pull request Aug 25, 2025
qiqizjl pushed a commit to qiqizjl/dify that referenced this pull request Aug 27, 2025
Signed-off-by: Yongtao Huang <yongtaoh2022@gmail.com>
Co-authored-by: Yongtao Huang <99629139+hyongtao-db@users.noreply.github.com>
HarryReidx pushed a commit to HarryReidx/dify that referenced this pull request Sep 1, 2025
Signed-off-by: Yongtao Huang <yongtaoh2022@gmail.com>
Co-authored-by: Yongtao Huang <99629139+hyongtao-db@users.noreply.github.com>
(cherry picked from commit 9a18911)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

raise exception be ignored

3 participants