Closed rjwignar closed 2 months ago
Latest commit: |
46b569e
|
Status: | ✅ Deploy successful! |
Preview URL: | https://08d7b6bb.console-overthinker-dev.pages.dev |
Branch Preview URL: | https://issue-605.console-overthinker-dev.pages.dev |
Closing as we're exploring #625 instead
This fixes #605
Background
Currently, if you use /import with a Youtube video that either has no captions or English subtitles, ChatCraft will throw this Error Toast:
This Error Toast isn't very descriptive.
When /import successfully parses YouTube video captions,
.
res.text()
returns the actual content that populates the Message:However, if /import (when using youtube-captions-scraper) fails to do so (either due to no captions in specified language or no captions at all), res.text() returns the HTML of a CloudFlare Worker error page:
We only want the actual error message, nested inside the html content:![image](https://github.com/tarasglek/chatcraft.org/assets/78163326/e94faf3e-0368-4909-9fb6-971d038b5061)
Solution
I tried modifying the error handling in youtube-rewriter.ts and in proxy.ts (API handler for /import command) so res.text() would contain just the error message, but it seems no matter what I did, a bad response would always return HTML in res.text().
Instead, I decided to use Cheerio (already installed) to extract the error message from any bad responses that have an HTML type. I kept the old error message in case other error responses don't contain HTML.
The result is that if /import fails on a YouTube video, the user will get a useful Error Toast telling them why: No English captions (https://www.youtube.com/watch?v=y6120QOlsfU):![image](https://github.com/tarasglek/chatcraft.org/assets/78163326/9b7650b9-6d88-4351-bf59-1c121c6078c4)
No captions at all (https://www.youtube.com/watch?v=TKfS5zVfGBc):![image](https://github.com/tarasglek/chatcraft.org/assets/78163326/b49709ad-75bc-4d00-a289-b42d8a4fc22a)