From f3c60d359bec8135bbf15e251b82c48897610ee9 Mon Sep 17 00:00:00 2001 From: EnixCoda Date: Wed, 4 Mar 2020 22:14:06 +0800 Subject: [PATCH] fix: enrich log for content type errors --- src/utils/GitHubHelper.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/utils/GitHubHelper.ts b/src/utils/GitHubHelper.ts index 2d7ef96..d11a4cc 100644 --- a/src/utils/GitHubHelper.ts +++ b/src/utils/GitHubHelper.ts @@ -32,9 +32,11 @@ async function request(url: string, { accessToken }: Options = {}) { headers.Authorization = `token ${accessToken}` } const res = await fetch(url, { headers }) - const contentType = res.headers.get('Content-Type') - if (!contentType || !contentType.includes('application/json')) { - throw new Error(`Response content is not JSON`) + const contentType = res.headers.get('Content-Type') || res.headers.get('content-type') + if (!contentType) { + throw new Error(`Response has no content type`) + } else if (!contentType.includes('application/json')) { + throw new Error(`Response content type is ${contentType}`) } // About res.ok: // True if res.status between 200~299