mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
fix: enrich log for content type errors
This commit is contained in:
parent
b6e7833079
commit
f3c60d359b
1 changed files with 5 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue