fix(api): surface YouTube action failures as 422, not 502
Same fix as the subscribe reconcile, applied to the remaining endpoints that wrapped a YouTubeError in a 502: video lookup (feed) and playlist refresh, push-plan, sync, and delete. A 502 is treated by the client as a transient "connection lost" blip, so a real, explainable YouTube failure showed the wrong message. 422 carries the clear detail to the error dialog instead.
This commit is contained in:
parent
6dde2ad732
commit
89bc0403e5
2 changed files with 5 additions and 5 deletions
|
|
@ -552,7 +552,7 @@ def get_video_detail(
|
|||
with quota.attribute(user.id, "video_lookup"), YouTubeClient(db, user) as yt:
|
||||
items = yt.get_videos([video_id])
|
||||
except YouTubeError as exc:
|
||||
raise HTTPException(status_code=502, detail=f"YouTube lookup failed: {exc}")
|
||||
raise HTTPException(status_code=422, detail=f"YouTube lookup failed: {exc}")
|
||||
if not items:
|
||||
raise HTTPException(status_code=404, detail="Unknown video")
|
||||
|
||||
|
|
|
|||
|
|
@ -270,7 +270,7 @@ def revert_youtube(
|
|||
return repull_playlist(db, user, pl)
|
||||
except YouTubeError:
|
||||
db.rollback()
|
||||
raise HTTPException(status_code=502, detail="Couldn't refresh from YouTube.")
|
||||
raise HTTPException(status_code=422, detail="Couldn't refresh from YouTube.")
|
||||
|
||||
|
||||
def _pushable(db: Session, user: User, playlist_id: int) -> Playlist:
|
||||
|
|
@ -301,7 +301,7 @@ def push_plan(
|
|||
with quota.attribute(user.id, "playlist_push"):
|
||||
plan = plan_push(db, user, pl)
|
||||
except YouTubeError:
|
||||
raise HTTPException(status_code=502, detail="Couldn't read the playlist on YouTube.")
|
||||
raise HTTPException(status_code=422, detail="Couldn't read the playlist on YouTube.")
|
||||
plan["remaining_today"] = quota.remaining_today(db)
|
||||
plan["affordable"] = plan["units_estimate"] <= plan["remaining_today"]
|
||||
return plan
|
||||
|
|
@ -332,7 +332,7 @@ def push(
|
|||
return push_playlist(db, user, pl)
|
||||
except YouTubeError:
|
||||
db.rollback()
|
||||
raise HTTPException(status_code=502, detail="YouTube playlist sync failed.")
|
||||
raise HTTPException(status_code=422, detail="YouTube playlist sync failed.")
|
||||
|
||||
|
||||
@router.get("/{playlist_id}")
|
||||
|
|
@ -422,7 +422,7 @@ def delete_playlist(
|
|||
with YouTubeClient(db, user) as yt:
|
||||
yt.delete_playlist(pl.yt_playlist_id)
|
||||
except YouTubeError:
|
||||
raise HTTPException(status_code=502, detail="YouTube delete failed.")
|
||||
raise HTTPException(status_code=422, detail="YouTube delete failed.")
|
||||
db.delete(pl) # items cascade
|
||||
db.commit()
|
||||
return {"deleted": playlist_id}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue