mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-03-02 22:57:32 -05:00
Web API error handling + standard response #8914
Labels
No labels
Accessibility
AppImage
Bounty
Build system
CI
Can't reproduce
Code cleanup
Confirmed bug
Confirmed bug
Core
Crash
Data loss
Discussion
Docker
Documentation
Duplicate
Feature
Feature request
Feature request
Feature request
Filters
Flatpak
GUI
Has workaround
I2P
Invalid
Libtorrent
Look and feel
Meta
NSIS
Network
Not an issue
OS: *BSD
OS: Linux
OS: Windows
OS: macOS
PPA
Performance
Project management
Proxy/VPN
Qt bugs
Qt6 compat
RSS
Search engine
Security
Temp folder
Themes
Translations
Triggers
Waiting diagnosis
Waiting info
Waiting upstream
Waiting web implementation
Watched folders
WebAPI
WebUI
autoCloseOldIssue
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/qBittorrent#8914
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Piccirello on GitHub (Jul 22, 2019).
The Web API should provide more granular results and well defined behavior when executing a request and handling errors. This issue is to discuss the format for the standard Web API response.
@Piccirello commented on GitHub (Jul 22, 2019):
This is my proposal for the api response. It's intended to be simple and concise.
API Response
For example, imagine a POST request to
/api/v2/torrents/addTrackerswith a validhashand twourls. The first hash is valid and the second is invalid. The response would look like this:@glassez commented on GitHub (Jul 22, 2019):
Sorry, it has a little meaning without detailed description.
@Piccirello commented on GitHub (Jul 22, 2019):
I've added more info to the proposal.
@Piccirello commented on GitHub (Aug 19, 2019):
@glassez do you have any thoughts on this proposal?
@glassez commented on GitHub (Aug 21, 2019):
Yes.
I just don't have time to do it all at once, so I'm commenting on the higher priority issues/PRs first.
In addition, I'm not very comfortable writing code samples from my smartphone, so I'll do it as soon as I'm near my computer in my free time.
@glassez commented on GitHub (Aug 31, 2019):
This is my proposal for the API response. IMO, it's simpler and more flexible than @Piccirello's proposal.
Single-job response:
Multijob response:
@Piccirello commented on GitHub (Apr 25, 2020):
I'm in favor of the global status codes you proposed. I would still like to see a top-level count of the number of items that failed/succeeded. Mapping multi-job responses by ids does make more sense than array indexing.
Multijob response:
I also think we should be more prescriptive about the action-defined fields. Copied from above:
@glassez commented on GitHub (Apr 26, 2020):
What sense do you find in it? After all, you still have to process them all.
However, I won't mind too much if you want to complicate it. Maybe it's really useful for something.
I agree generally. But I would have "status: OK|Failed" instead of your "success" field. And "errorMessage" instead of "error" (it should be optional and exist only in case of "status: Failed"). Or maybe pass error message in "data" field instead?
This looks like a loophole for ambiguity... it may not match the actual values from the subtask results.
But of course, this can be avoided by implementing automatic filling in of these fields in API controllers. We can provide
addResult(int status, QJsonValue data)that accumulates results and calculate total numbers of succeeded/failed ones.The only thing I don't like is that each Action will be responsible for maintaining consistency of its result (i.e. if it is "multijob" action, it should always return "multijob" result, and vice versa). Shouldn't we completely unify this? So that all Actions return the Result in the same form (as "multijob" one, but "singlejob" Actions will always have only one element in it).
@Piccirello commented on GitHub (Apr 26, 2020):
I was agreeing with you! My original proposal had
responsesas an array, but you suggested instead using aresultmap that's mapped by job id, which I can get behind.Agreed on using
errorinstead oferrorMessage, though I'd keep it outside ofdata. It lends itself well to a general rule: if successful, use thedatafield, otherwise useerror.If
OkandFailedare they only two possiblestatusvalues than a boolean still seems more straightforward to me.+1 on this method.
I was pondering this as well. While I prefer single-job actions to return a single response (no array), from an implementation standpoint it is definitely less error prone to treat every response as multi-job. I'm fine with either.
@glassez commented on GitHub (Apr 27, 2020):
No. I suppose that there should be several error statuses to indicate different kind of errors that can be handled differently at the client side.
As for
errorfield. I still believe that returning error description strings from API is generally bad idea. IMO, it's good point to differentiate the data and its representation (in case of error too). So I would return error status/code and let client application to represent it.But since statuses/codes alone are not enough to provide all the necessary information about some errors (for example, file names, etc.), we could return in
errorfield something like an "exception object" that stores all the necessary data. Then it will be enough for us to have a boolean type for thestatusfield, and the specific error code will be in the "exception object".@glassez commented on GitHub (Apr 27, 2020):
👍
If we can find a convenient and reliable way to declare various types of Actions (multijob and singlejob), I will prefer it.