Skip to content

Conversation

@finevan
Copy link

@finevan finevan commented Nov 24, 2025

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.

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.
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")
Copy link
Author

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

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)
Copy link
Author

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

@finevan finevan requested a review from s0up4200 November 25, 2025 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants