diff options
author | 2021-08-14 09:21:34 -0400 | |
---|---|---|
committer | 2021-08-14 20:21:34 +0700 | |
commit | ac8de6bd0ef0a6016732a69556e4eb9c014cfd38 (patch) | |
tree | c91eb73907b2d1443b9cc216116c9347ef499097 /source/github-helpers/api.ts | |
parent | 5ec0ec56dae43b328141453957dd9e53c69dd71e (diff) | |
download | refined-github-ac8de6bd0ef0a6016732a69556e4eb9c014cfd38.tar.gz refined-github-ac8de6bd0ef0a6016732a69556e4eb9c014cfd38.tar.zst refined-github-ac8de6bd0ef0a6016732a69556e4eb9c014cfd38.zip |
Meta: Log API calls and other fetches (#4656)21.8.14
Diffstat (limited to 'source/github-helpers/api.ts')
-rw-r--r-- | source/github-helpers/api.ts | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/source/github-helpers/api.ts b/source/github-helpers/api.ts index 386156ac..45860893 100644 --- a/source/github-helpers/api.ts +++ b/source/github-helpers/api.ts @@ -48,6 +48,13 @@ interface RestResponse extends AnyObject { ok: boolean; } +export async function log(message: string): Promise<void> { + const {logAPI} = (await optionsStorage.getAll()); + if (logAPI) { + console.log(message); + } +} + export const escapeKey = (value: string | number): string => '_' + String(value).replace(/[ ./-]/g, '_'); export class RefinedGitHubAPIError extends Error { @@ -118,6 +125,7 @@ export const v3 = mem(async ( } const url = new URL(query, api3); + void log(String(url)); const response = await fetch(url.href, { method, body: body && JSON.stringify(body), @@ -174,6 +182,10 @@ export const v4 = mem(async ( query = query.replace('repository() {', () => `repository(owner: "${getRepo()!.owner}", name: "${getRepo()!.name}") {`); + void log(`{ + ${query} + }`); + const response = await fetch(api4, { headers: { 'User-Agent': 'Refined GitHub', |