Skip to content

Commit b4b02a9

Browse files
committed
more error logging
1 parent 59465d8 commit b4b02a9

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default {
1414
};
1515

1616
class GitHubApiError extends Error {
17-
constructor(public status: number) {
17+
constructor(public status: number, public url: string, public body: string) {
1818
super(`GitHub API error: ${status}`);
1919
}
2020
}
@@ -29,7 +29,8 @@ async function ghFetch(url: string, env: Env): Promise<any> {
2929
}
3030
});
3131
if (!res.ok) {
32-
throw new GitHubApiError(res.status);
32+
const body = await res.text();
33+
throw new GitHubApiError(res.status, url, body);
3334
}
3435
return res.json();
3536
}
@@ -44,7 +45,7 @@ async function handleList(env: Env) {
4445
deliveries = await ghFetch(`${apiBase(env)}/deliveries?per_page=20`, env);
4546
} catch (e) {
4647
if (e instanceof GitHubApiError) {
47-
return new Response(`GitHub API error: ${e.status}`, { status: 502 });
48+
return new Response(`GitHub API error: ${e.status}\nURL: ${e.url}\n${e.body}`, { status: 502 });
4849
}
4950
throw e;
5051
}
@@ -86,7 +87,7 @@ async function handleSingleDelivery(id: string, env: Env) {
8687
delivery = await ghFetch(`${apiBase(env)}/deliveries/${id}`, env);
8788
} catch (e) {
8889
if (e instanceof GitHubApiError) {
89-
return new Response(`GitHub API error: ${e.status}`, { status: 502 });
90+
return new Response(`GitHub API error: ${e.status}\nURL: ${e.url}\n${e.body}`, { status: 502 });
9091
}
9192
throw e;
9293
}

0 commit comments

Comments
 (0)