feat: not upload 404 error

This commit is contained in:
EnixCoda 2018-10-27 18:12:20 +08:00
parent b663ca052a
commit ff5806af68
No known key found for this signature in database
GPG key ID: 0C1A07377913A1DD

View file

@ -8,12 +8,12 @@ async function request(url, { accessToken } = {}) {
headers.Authorization = `token ${accessToken}`
}
const res = await fetch(url, { headers })
if (!res.ok) raiseError(new Error(`Got ${res.statusText} when requesting ${url}`))
if (res.status === 200) return res.json()
// for private repo, GitHub api also responses with 404 when unauthorized
if (res.status === 404) throw new Error(NOT_FOUND)
else if (res.status === 404) throw new Error(NOT_FOUND)
else if (!res.ok) raiseError(new Error(`Got ${res.statusText} when requesting ${url}`))
const content = await res.json()
throw new Error(content.message)
throw new Error(content && content.message)
}
async function getRepoMeta({ userName, repoName, accessToken }) {