mirror of
https://github.com/ramsayleung/rspotify.git
synced 2026-04-26 07:55:55 +03:00
[PR #258] [MERGED] HTTP Error cleanup #352
Labels
No labels
Stale
bug
discussion
enhancement
good first issue
good first issue
help wanted
pull-request
question
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/rspotify#352
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?
📋 Pull Request Information
Original PR: https://github.com/ramsayleung/rspotify/pull/258
Author: @marioortizmanero
Created: 9/25/2021
Status: ✅ Merged
Merged: 10/8/2021
Merged by: @ramsayleung
Base:
master← Head:errors📝 Commits (10+)
9bcd5b7Improved error handling80d9e3fSecond approachde330d6Use full names for errorsf8b7fbcSmall fixese97ec70Even better thanks to associated types!!ad74f81Fix main crate as welld58498aFix clippy lints about map_err467e039Actually fix clippy lintd3335d3More idiomatic returnf7fa8cfSimplify map_err📊 Changes
6 files changed (+151 additions, -95 deletions)
View changed files
📝
rspotify-http/Cargo.toml(+4 -2)📝
rspotify-http/src/common.rs(+7 -29)📝
rspotify-http/src/lib.rs(+3 -3)📝
rspotify-http/src/reqwest.rs(+50 -44)📝
rspotify-http/src/ureq.rs(+76 -16)📝
src/lib.rs(+11 -1)📄 Description
Description
This cleans up the errors for
rspotify-http, according to #137.I would say the rest of the error types are OK, so this closes #137.
Motivation and Context
The current error type for http tries to wrap up all the errors from the clients we support under the same interface. However, it's a mess because:
HttpError::Iois only needed for ureqRateLimitedorUnauthorizedbut it'sStatusCodefor the rest?ApiandStatusCodevariants the same?So this PR attempts to fix it by simply having a variant of error for each client supported by
rspotify-http. It's as easy as delegating error handling to the HTTP client. If the user has enabledureq, then they should deal withureq::Errorinstead of some wrapper of our own that might not have everything they need.This way, error handling is complete. There is nothing of functionality we miss by wrapping all of them under the same interface. And we also don't have to maintain such a complex wrapper ourselves.
I remember that @hrkfdn pointed out that the
RateLimitedvariant was a must for him in order to retry a request. Well, this design still makes it possible to do so. It's just dependent on what HTTP client he's using. If he uses reqwest then it should be something like:And if someone wanted to get the API error from Spotify:
Dependencies
None
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
The CI still passes
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.