[PR #112] [MERGED] [boosty-api] Fix wrong-username errors and non-JSON body crash #117

Closed
opened 2026-10-13 19:47:33 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Glitchy-Sheep/boosty-downloader/pull/112
Author: @Glitchy-Sheep
Created: 8/7/2026
Status: ✅ Merged
Merged: 8/7/2026
Merged by: @Glitchy-Sheep

Base: main ← Head: fix/api-error-mapping


📝 Commits (2)

  • 5781e39 fix: 🐛 Map Boosty API errors before parsing the body (#94)
  • 76dd39b test: ✅ Add regression tests for API client error mapping

📊 Changes

5 files changed (+168 additions, -4 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 boosty_downloader/main.py (+12 -2)
📝 boosty_downloader/src/infrastructure/boosty_api/core/client.py (+24 -2)
➕ test/unit/boosty_api/__init__.py (+0 -0)
➕ test/unit/boosty_api/client_test.py (+131 -0)

📄 Description

Summary

Wrong usernames now get clear messages instead of a scary "report this at GitHub" error, and a non-JSON reply from the API no longer crashes the app. Fixes #94.

Problem

  • The client parsed the response body before looking at the status code
  • So an error reply with a non-JSON body (e.g. a DDoS-protection challenge page) crashed with a raw ContentTypeError traceback
  • A typo in the username (404) printed a bare "Username not found" without the name or any hint
  • An email instead of a username (Boosty answers 400 invalid_param) fell into the generic "Unknown error occurred, please report this at GitHub issues" - that is how #94 was born

Fix

  • Check the status code first: 404, 401, 400, then everything else
  • New BoostyAPIInvalidUsernameError for 400 with its own message for the email case
  • Parse the body only after the status checks; a non-JSON body on 200 maps to BoostyAPIUnknownError
  • Both username messages show the entered name and a hint: username is the blog name from boosty.to/<name>

Before / After

Before: download -u someone@gmail.com ends with "Unknown error occurred, please report this at GitHub issues".

After: it says "'someone@gmail.com' is not a valid username. Use the blog name from the author page URL (boosty.to/<username>), not an email".

Tests

  • test_404_maps_to_no_username_error_without_parsing_body - 404 gives "author not found" and the body is never parsed
  • test_401_maps_to_unauthorized_error_without_parsing_body - expired tokens keep the "relogin" message
  • test_400_maps_to_invalid_username_error_without_parsing_body - the email case from #94
  • test_unexpected_status_maps_to_unknown_error - 5xx with an HTML body no longer crashes
  • test_200_with_non_json_body_maps_to_unknown_error - wrong content-type and broken JSON on 200 map to a clear error
  • test_200_with_valid_empty_page_returns_posts_response - the happy path still parses

Notes

  • Error reply shapes (400 invalid_param, 404 blog_not_found) checked by hand against the live API

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Glitchy-Sheep/boosty-downloader/pull/112 **Author:** [@Glitchy-Sheep](https://github.com/Glitchy-Sheep) **Created:** 8/7/2026 **Status:** ✅ Merged **Merged:** 8/7/2026 **Merged by:** [@Glitchy-Sheep](https://github.com/Glitchy-Sheep) **Base:** `main` ← **Head:** `fix/api-error-mapping` --- ### 📝 Commits (2) - [`5781e39`](https://github.com/Glitchy-Sheep/boosty-downloader/commit/5781e39edfb5b7e66bdaece83667b94b94c4346a) fix: :bug: Map Boosty API errors before parsing the body (#94) - [`76dd39b`](https://github.com/Glitchy-Sheep/boosty-downloader/commit/76dd39bc3d31701878bde4e65a21c9f01a31b88a) test: :white_check_mark: Add regression tests for API client error mapping ### 📊 Changes **5 files changed** (+168 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `boosty_downloader/main.py` (+12 -2) 📝 `boosty_downloader/src/infrastructure/boosty_api/core/client.py` (+24 -2) ➕ `test/unit/boosty_api/__init__.py` (+0 -0) ➕ `test/unit/boosty_api/client_test.py` (+131 -0) </details> ### 📄 Description ## Summary Wrong usernames now get clear messages instead of a scary "report this at GitHub" error, and a non-JSON reply from the API no longer crashes the app. Fixes #94. ## Problem - The client parsed the response body before looking at the status code - So an error reply with a non-JSON body (e.g. a DDoS-protection challenge page) crashed with a raw ContentTypeError traceback - A typo in the username (404) printed a bare "Username not found" without the name or any hint - An email instead of a username (Boosty answers 400 `invalid_param`) fell into the generic "Unknown error occurred, please report this at GitHub issues" - that is how #94 was born ## Fix - Check the status code first: 404, 401, 400, then everything else - New `BoostyAPIInvalidUsernameError` for 400 with its own message for the email case - Parse the body only after the status checks; a non-JSON body on 200 maps to `BoostyAPIUnknownError` - Both username messages show the entered name and a hint: username is the blog name from boosty.to/&lt;name&gt; ## Before / After **Before:** `download -u someone@gmail.com` ends with "Unknown error occurred, please report this at GitHub issues". **After:** it says "'someone@gmail.com' is not a valid username. Use the blog name from the author page URL (boosty.to/&lt;username&gt;), not an email". ## Tests - `test_404_maps_to_no_username_error_without_parsing_body` - 404 gives "author not found" and the body is never parsed - `test_401_maps_to_unauthorized_error_without_parsing_body` - expired tokens keep the "relogin" message - `test_400_maps_to_invalid_username_error_without_parsing_body` - the email case from #94 - `test_unexpected_status_maps_to_unknown_error` - 5xx with an HTML body no longer crashes - `test_200_with_non_json_body_maps_to_unknown_error` - wrong content-type and broken JSON on 200 map to a clear error - `test_200_with_valid_empty_page_returns_posts_response` - the happy path still parses ## Notes - Error reply shapes (400 `invalid_param`, 404 `blog_not_found`) checked by hand against the live API --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-13 19:47:33 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Glitchy-Sheep/boosty-downloader#117
No description provided.