mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
feat: raise GitHub helper errors
This commit is contained in:
parent
e75a06a7ed
commit
197d0778d4
1 changed files with 2 additions and 0 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import { raiseError } from '../analytics'
|
||||
export const NOT_FOUND = 'Repo Not Found'
|
||||
export const BAD_CREDENTIALS = 'Bad credentials'
|
||||
|
||||
|
|
@ -7,6 +8,7 @@ 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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue