-
Notifications
You must be signed in to change notification settings - Fork 20
All client methods in methods.go verify the response http status code #98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
finevan
wants to merge
3
commits into
autobrr:main
Choose a base branch
from
finevan:finevan/all_methods_check_status
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+124
−4
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Previously the status code was not checked, so bad base paths or reverse proxies in front of unavailable qbittorrent instances would not trip the health check. There are several other endpoints which don't check the response status codes, I'd be happy to update them in follow-up commits.
While most endpoints unmarshal json, which will error on unexpected responses, verifying the status code first is less expensive, and provides more accurate and descriptive failure messages in the logs. I have verified each endpoints response statuses in the official qbittorrent documentation, with the exception of `torrents/export`, which is not documented. For this endpoint I have implemented specific handling for 404 not found, but left the 409 conflict status to fall through to the default unknown status branch, based on the qbittorrent implementation: https://github.com/qbittorrent/qBittorrent/blob/a77b17e6dafadca1eb0f80d4c0167c791107f787/src/webui/api/torrentscontroller.cpp#L2045-L2059 The qbittorrent 409 conflict status code seems questionable, as the failure appers not to be related to the request, so it would make more sense as a 5xx rather than 4xx status class, and I wouldn't be surprised if this changed in the future. This is a follow-up to autobrr#97 which handles the rest of the endpoints.
finevan
commented
Nov 24, 2025
| resp, err := c.getCtx(ctx, "torrents/properties", opts) | ||
| if err != nil { | ||
| return prop, errors.Wrap(err, "could not get app preferences") | ||
| return prop, errors.Wrap(err, "could not get torrent properties") |
Author
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed a likely copy/paste error in the message
finevan
commented
Nov 24, 2025
Comment on lines
-1986
to
+2064
| errors.Wrap(ErrUnexpectedStatus, "could not set share limits; hashes: %v | ratioLimit: %v | seedingTimeLimit: %v | inactiveSeedingTimeLimit %v | status code: %d", hashes, ratioLimit, seedingTimeLimit, inactiveSeedingTimeLimit, resp.StatusCode) | ||
| return errors.Wrap(ErrUnexpectedStatus, "could not set share limits; hashes: %v | ratioLimit: %v | seedingTimeLimit: %v | inactiveSeedingTimeLimit %v | status code: %d", hashes, ratioLimit, seedingTimeLimit, inactiveSeedingTimeLimit, resp.StatusCode) |
Author
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously this created an error that was not returned, and fell through to the return nil path below
s0up4200
requested changes
Nov 25, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While most endpoints unmarshal json, which will error on unexpected responses, verifying the status code first is less expensive, and provides more accurate and descriptive failure messages in the logs.
I have verified each endpoints response statuses in the official qbittorrent documentation, with the exception of
torrents/export, which is not documented. For this endpoint I have implemented specific handling for 404 not found, but left the 409 conflict status to fall through to the default unknown status branch, based on the qbittorrent implementation:https://github.com/qbittorrent/qBittorrent/blob/a77b17e6dafadca1eb0f80d4c0167c791107f787/src/webui/api/torrentscontroller.cpp#L2045-L2059 The qbittorrent 409 conflict status code seems questionable, as the failure appers not to be related to the request, so it would make more sense as a 5xx rather than 4xx status class, and I wouldn't be surprised if this changed in the future.
This is a follow-up to #97 which handles the rest of the endpoints. Currently this include the commit from #97, I can rebase if that PR merges first, or we can move forward with this in its place.