fix: surface Spotify quota exhaustion
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
358d058392
commit
bfea9efb5e
6 changed files with 97 additions and 10 deletions
|
|
@ -38,6 +38,8 @@ from app.ports.protocols import (
|
|||
RERANK_FALLBACK_CODE = "rerank_fallback"
|
||||
RERANK_FALLBACK_MESSAGE = "Ranking output was invalid, so grounded results are shown instead."
|
||||
RERANK_FALLBACK_JUSTIFICATION = "Selected as a grounded match for your request."
|
||||
QUOTA_ERROR_CODE = "quota_exhausted"
|
||||
QUOTA_ERROR_MESSAGE = "Spotify's Development Mode quota is temporarily exhausted."
|
||||
|
||||
|
||||
class _TrackSelection:
|
||||
|
|
@ -140,10 +142,8 @@ class RecommendationPipeline:
|
|||
return
|
||||
except CatalogQuotaExhaustedError:
|
||||
yield PipelineErrorEvent(
|
||||
code="quota_exhausted",
|
||||
message=(
|
||||
"Spotify request quota was exhausted before recommendations could be prepared."
|
||||
),
|
||||
code=QUOTA_ERROR_CODE,
|
||||
message=QUOTA_ERROR_MESSAGE,
|
||||
)
|
||||
return
|
||||
except SpotifyError:
|
||||
|
|
@ -158,9 +158,16 @@ class RecommendationPipeline:
|
|||
candidate_count=len(intent.candidates),
|
||||
)
|
||||
|
||||
pool = await self._grounded_pool(
|
||||
session_id, catalog, intent, taste, deadline_at, seeded_pool
|
||||
)
|
||||
try:
|
||||
pool = await self._grounded_pool(
|
||||
session_id, catalog, intent, taste, deadline_at, seeded_pool
|
||||
)
|
||||
except CatalogQuotaExhaustedError:
|
||||
yield PipelineErrorEvent(
|
||||
code=QUOTA_ERROR_CODE,
|
||||
message=QUOTA_ERROR_MESSAGE,
|
||||
)
|
||||
return
|
||||
if not pool:
|
||||
yield PipelineErrorEvent(
|
||||
code="no_grounded_results",
|
||||
|
|
@ -209,6 +216,8 @@ class RecommendationPipeline:
|
|||
self.settings.rerank_count + self.settings.rerank_pool_buffer,
|
||||
deadline_at,
|
||||
)
|
||||
if not result.tracks and result.metrics.did_exhaust_quota:
|
||||
raise CatalogQuotaExhaustedError
|
||||
if result.tracks:
|
||||
self.last_pools[session_id] = result.tracks
|
||||
return result.tracks
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue