[PR #19948] Feat(WaterCrawl error handling): add custom exceptions and error handling #29275

Closed
opened 2026-02-21 20:45:13 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/19948

State: closed
Merged: Yes


Summary

  • Added WaterCrawlError as base exception class
  • Implemented WaterCrawlBadRequestError for 400-level errors
  • Added WaterCrawlPermissionError for 403 Forbidden errors
  • Added WaterCrawlAuthenticationError for 401 Unauthorized errors
  • Updated process_response to raise appropriate exceptions
  • Included detailed error messages and response handling

Issues

Resolve #18229
Related #15950

Description

I noticed that the Dify implementation currently lacks error handling for 4xx and 5xx HTTP responses in web crawling. Other website crawl providers typically raise a ValueError or a similar exception in these cases. I've followed that approach and implemented custom exceptions with more descriptive messages to clarify the cause of the error.

If you plan to implement a more robust error transformation system for handling third-party errors in the future, I’d be happy to update my code accordingly. However, as shown in the code below, the current system seems to only accept unhandled exceptions or 200 OK responses.

https://github.com/langgenius/dify/blob/276c02f341b08c7bd7a258e7ec62c4a9ff8f2c72/api/controllers/console/datasets/website.py#L28-L33

Screenshots

Before After
Screenshot 2025-05-19 at 9 27 32 PM Screenshot 2025-05-19 at 11 28 04 AM

Checklist

  • 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
**Original Pull Request:** https://github.com/langgenius/dify/pull/19948 **State:** closed **Merged:** Yes --- # Summary - Added WaterCrawlError as base exception class - Implemented WaterCrawlBadRequestError for 400-level errors - Added WaterCrawlPermissionError for 403 Forbidden errors - Added WaterCrawlAuthenticationError for 401 Unauthorized errors - Updated process_response to raise appropriate exceptions - Included detailed error messages and response handling ## Issues Resolve #18229 Related #15950 # Description I noticed that the Dify implementation currently lacks error handling for 4xx and 5xx HTTP responses in web crawling. Other website crawl providers typically raise a ValueError or a similar exception in these cases. I've followed that approach and implemented custom exceptions with more descriptive messages to clarify the cause of the error. If you plan to implement a more robust error transformation system for handling third-party errors in the future, I’d be happy to update my code accordingly. However, as shown in the code below, the current system seems to only accept unhandled exceptions or 200 OK responses. https://github.com/langgenius/dify/blob/276c02f341b08c7bd7a258e7ec62c4a9ff8f2c72/api/controllers/console/datasets/website.py#L28-L33 # Screenshots | Before | After | |--------|-------| | <img width="445" alt="Screenshot 2025-05-19 at 9 27 32 PM" src="https://github.com/user-attachments/assets/0d8be548-8e17-4191-9d6a-d851712e1fd7" /> | <img width="484" alt="Screenshot 2025-05-19 at 11 28 04 AM" src="https://github.com/user-attachments/assets/de17125c-3009-4d4d-8117-d8de8d458547" /> | # Checklist - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods
yindo added the pull-request label 2026-02-21 20:45:13 -05:00
yindo closed this issue 2026-02-21 20:45:13 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#29275