MCPcopy Index your code
hub / github.com/ChatLab/ChatLab / fetchWithAuth

Function fetchWithAuth

src/services/utils/http.ts:61–71  ·  view source on GitHub ↗
(url: string, init?: RequestInit)

Source from the content-addressed store, hash-verified

59 * Electron Internal Server mode works with absolute base URLs.
60 */
61export 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
73function handle401(resp: Response): void {
74 if (resp.status === 401 && _on401) _on401()

Callers 15

fetchJsonFunction · 0.90
fetchSyncProgressFunction · 0.90
installMergeShimsFunction · 0.90
http.test.tsFile · 0.90
fetchSSEFunction · 0.90
importFileMethod · 0.90
detectFormatMethod · 0.90
scanMultiChatFileMethod · 0.90
prepareImportSourceMethod · 0.90
importPreparedChatMethod · 0.90
releaseImportSourceMethod · 0.90
importDemoMethod · 0.90

Calls 3

resolveTokenFunction · 0.85
resolveFullUrlFunction · 0.85
setMethod · 0.80

Tested by

no test coverage detected