From 8ea6313969755cb0ee2c2020d3984442e2e13245 Mon Sep 17 00:00:00 2001 From: Cory Dransfeldt Date: Sun, 14 Apr 2024 09:54:19 -0700 Subject: [PATCH] fix: handle errors better --- api/now-playing.js | 3 +++ package.json | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/api/now-playing.js b/api/now-playing.js index 84f0af83..13c1a39e 100644 --- a/api/now-playing.js +++ b/api/now-playing.js @@ -85,6 +85,7 @@ export default async () => { }, }) .then((data) => { + if (data.status) return {} if (data.ok) return data?.json(); throw new Error('Something went wrong with the Trakt endpoint.'); }) @@ -113,6 +114,8 @@ export default async () => { const scrobbleData = await scrobbles.get('now-playing', { type: 'json'}) + if (!scrobbleData) return new Response(JSON.stringify({}, { headers })) + return new Response(JSON.stringify({ content: `${emojiMap( scrobbleData['genre'], diff --git a/package.json b/package.json index 90fe756f..56c7fd64 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "coryd.dev", - "version": "10.1.1", + "version": "10.1.2", "description": "The source for my personal site. Built using 11ty.", "type": "module", "scripts": {