( path: string, config: RequestConfig, parser = (response: Response) => parseResponse(response), )
| 193 | } |
| 194 | |
| 195 | export async function apiRequest( |
| 196 | path: string, |
| 197 | config: RequestConfig, |
| 198 | parser = (response: Response) => parseResponse(response), |
| 199 | ) { |
| 200 | const { token, backend, ...props } = config; |
| 201 | const options = { cache: 'no-cache', ...props }; |
| 202 | const headers = await constructRequestHeaders({ headers: options.headers || {}, token }); |
| 203 | const baseUrl = config.apiRoot ?? apiRoots[backend]; |
| 204 | const url = constructUrlWithParams(`${baseUrl}${path}`, options.params); |
| 205 | let responseStatus = 500; |
| 206 | try { |
| 207 | const req = unsentRequest.fromFetchArguments(url, { |
| 208 | ...options, |
| 209 | headers, |
| 210 | }) as unknown as ApiRequest; |
| 211 | const response = await requestWithBackoff(api, req); |
| 212 | responseStatus = response.status; |
| 213 | const parsedResponse = await parser(response); |
| 214 | return parsedResponse; |
| 215 | } catch (error) { |
| 216 | return handleRequestError(error, responseStatus, backend); |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | export async function getDefaultBranchName(configs: { |
| 221 | backend: Backend; |
no test coverage detected