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) } }