Files
remanso/src/modules/repo/services/octo.ts
Julien Calixte fc4ed188d7 feat(repo): add Octokit request timeouts and retry UI
Before, every GitHub call awaited indefinitely with no AbortSignal,
so a "lie-fi" connection (technically online, effectively dead) left
FluxNote stuck on the skeleton loader and the freshness badge spinning
forever. Inject an 8s AbortSignal.timeout via octokit.hook.before
(20s override on the recursive tree fetch), classify failures in the
userRepo store as auth vs network, and surface a "Couldn't reach
GitHub" retry button when no cached content is available.
2026-05-16 23:28:11 +02:00

23 lines
545 B
TypeScript

import { Octokit } from "@octokit/rest"
import { getAccessToken } from "@/modules/user/service/signIn"
export const DEFAULT_OCTOKIT_TIMEOUT_MS = 8_000
export const getOctokit = async (): Promise<Octokit> => {
const response = await getAccessToken()
const octokit = new Octokit({
auth: response?.token ?? ""
})
octokit.hook.before("request", (options) => {
options.request ??= {}
if (!options.request.signal) {
options.request.signal = AbortSignal.timeout(DEFAULT_OCTOKIT_TIMEOUT_MS)
}
})
return octokit
}