(url: string, init?: RequestInit)
| 59 | * Electron Internal Server mode works with absolute base URLs. |
| 60 | */ |
| 61 | export async function fetchWithAuth(url: string, init?: RequestInit): Promise<Response> { |
| 62 | const headers = new Headers(init?.headers) |
| 63 | const token = resolveToken() |
| 64 | if (token && !headers.has('Authorization')) { |
| 65 | headers.set('Authorization', `Bearer ${token}`) |
| 66 | } |
| 67 | const resolvedUrl = resolveFullUrl(url) |
| 68 | const resp = await fetch(resolvedUrl, { ...init, headers }) |
| 69 | if (resp.status === 401 && _on401) _on401() |
| 70 | return resp |
| 71 | } |
| 72 | |
| 73 | function handle401(resp: Response): void { |
| 74 | if (resp.status === 401 && _on401) _on401() |
no test coverage detected