diff options
Diffstat (limited to '174bg/discord-bot/utilities/getUrl.js')
| -rw-r--r-- | 174bg/discord-bot/utilities/getUrl.js | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/174bg/discord-bot/utilities/getUrl.js b/174bg/discord-bot/utilities/getUrl.js index 49342d9..a6e22ef 100644 --- a/174bg/discord-bot/utilities/getUrl.js +++ b/174bg/discord-bot/utilities/getUrl.js @@ -1,5 +1,14 @@ export default async (url) => { const response = await fetch(url); + if (!response.ok) return null; - return await response.json(); + + // is it json? + const contentType = response.headers.get("content-type"); + if (contentType && contentType.includes("application/json")) { + return await response.json(); + } + + // fallback to text + return await response.text(); }; |
