(request: Request)
| 82 | } |
| 83 | |
| 84 | function githubFetch(request: Request): Promise<Response> { |
| 85 | return fetch(request).then(response => { |
| 86 | if (response.status === 401) { |
| 87 | token.value = null; |
| 88 | } |
| 89 | if (response.status === 403) { |
| 90 | response.json().then(data => { |
| 91 | if (data.message === 'Resource not accessible by integration') { |
| 92 | window.dispatchEvent(new CustomEvent('not-installed')); |
| 93 | } |
| 94 | }); |
| 95 | } |
| 96 | |
| 97 | processRateLimit(response); |
| 98 | |
| 99 | if (request.method === 'GET' |
| 100 | && [401, 403].indexOf(response.status) !== -1 |
| 101 | && request.headers.has('Authorization') |
| 102 | ) { |
| 103 | request.headers.delete('Authorization'); |
| 104 | return githubFetch(request); |
| 105 | } |
| 106 | return response; |
| 107 | }); |
| 108 | } |
| 109 | |
| 110 | export function loadJsonFile<T>(path: string, html = false) { |
| 111 | const request = githubRequest(`repos/${owner}/${repo}/contents/${path}?ref=${branch}`); |
no test coverage detected