Skip to content

Commit 51cdbbe

Browse files
[skip ci] Merge branch main into staging-38
2 parents 694d52b + 2706cca commit 51cdbbe

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

scripts/lib/executionUtils.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,14 @@ interface FetchError extends Error {
4646
export async function fetchHandlingError(url: string, options?: RequestInit): Promise<Response> {
4747
const response = await fetch(url, options)
4848
if (!response.ok) {
49-
const error = new Error(`HTTP Error Response: ${response.status} ${response.statusText}`) as FetchError
49+
let cause: unknown
50+
const body = await response.text()
51+
try {
52+
cause = JSON.parse(body)
53+
} catch {
54+
cause = body
55+
}
56+
const error = new Error(`HTTP Error Response: ${response.status} ${response.statusText}`, { cause }) as FetchError
5057
error.status = response.status
5158
throw error
5259
}

scripts/lib/gitUtils.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,17 @@ export function initGitConfig(repository: string): void {
110110
export const LOCAL_BRANCH = process.env.CI_COMMIT_REF_NAME
111111

112112
async function callGitHubApi<T>(method: string, path: string, token: OctoStsToken, body?: any): Promise<T> {
113-
const response = await fetchHandlingError(`https://api.github.com/repos/DataDog/browser-sdk/${path}`, {
114-
method,
115-
headers: {
116-
Authorization: `token ${token.value}`,
117-
'X-GitHub-Api-Version': '2022-11-28',
118-
},
119-
body: body ? JSON.stringify(body) : undefined,
120-
})
121-
return (await response.json()) as Promise<T>
113+
try {
114+
const response = await fetchHandlingError(`https://api.github.com/repos/DataDog/browser-sdk/${path}`, {
115+
method,
116+
headers: {
117+
Authorization: `token ${token.value}`,
118+
'X-GitHub-Api-Version': '2022-11-28',
119+
},
120+
body: body ? JSON.stringify(body) : undefined,
121+
})
122+
return (await response.json()) as Promise<T>
123+
} catch (error) {
124+
throw new Error(`Failed to call GitHub API: ${method} ${path}`, { cause: error })
125+
}
122126
}

0 commit comments

Comments
 (0)