Skip to content

Commit 85d2abc

Browse files
committed
fix: rate limit error and lyrics not found error returned as 422
1 parent 6b53e1a commit 85d2abc

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

src/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@ const app = new Elysia()
4949
rateLimit({
5050
max: 15,
5151
duration: 60_000,
52-
errorResponse: JSON.stringify({
53-
status: 'error',
54-
error: { message: 'Too many requests', timestamp: timestamp() },
55-
}),
52+
errorResponse: new Response(
53+
JSON.stringify({
54+
error: { message: 'Too many requests', timestamp: timestamp() },
55+
}),
56+
{ status: 429, headers: { 'Content-Type': 'application/json' } },
57+
),
5658
}),
5759
)
5860
.onError(({ code, error, set }) => {

src/routes/lyrics.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ async function handleLyricsRequest(query: LyricsQuery, request: Request): Promis
6161
return jsonError('Failed to fetch lyrics', 500, String(e))
6262
}
6363

64+
if (result.status === 'error') {
65+
const msg = (result.error as Record<string, unknown>)?.message
66+
return jsonError(typeof msg === 'string' ? msg : 'No lyrics found', 404)
67+
}
68+
6469
const data = result.data as Record<string, unknown> | undefined
6570
if (data?.lyrics) saveToCache(cacheKey, result)
6671

0 commit comments

Comments
 (0)