From 14fbce0285764a3b620dde001d5f1a950426bd63 Mon Sep 17 00:00:00 2001 From: silverpill Date: Sun, 19 Mar 2023 17:58:30 +0000 Subject: [PATCH] Show better error message if HTTP status code is 413 --- CHANGELOG.md | 4 ++++ src/api/common.ts | 11 +++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 869b79f..29d53e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] +### Changed + +- Show better error message if HTTP status code is 413. + ## [1.17.0] - 2023-03-15 ### Added diff --git a/src/api/common.ts b/src/api/common.ts index c139711..92a8d99 100644 --- a/src/api/common.ts +++ b/src/api/common.ts @@ -80,7 +80,14 @@ export async function handleResponse( return data } } else { - const data = await response.json() - throw new Error(data.error_description) + let errorDescription + if (response.headers.get("Content-Type") === "application/json") { + const data = await response.json() + errorDescription = data.error_description + } else { + // Unexpected response + errorDescription = response.statusText + } + throw new Error(errorDescription) } }