Skip to content

Commit 70ae4b6

Browse files
Merge pull request #52 from Andre-Diamond:main
Main
2 parents 7863af8 + 481a614 commit 70ae4b6

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

apps/shared-backend/github-actions/github-stats-action/getStats.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,25 @@ async function makeRequest(url, options = {}) {
8585
})
8686

8787
if (!response.ok) {
88-
throw new Error(`HTTP ${response.status}: ${response.statusText}`)
88+
// read response body for better diagnostics
89+
let errorBodyText = ''
90+
try {
91+
errorBodyText = await response.text()
92+
} catch (_) {
93+
// ignore
94+
}
95+
let parsedBody
96+
try {
97+
parsedBody = errorBodyText ? JSON.parse(errorBodyText) : undefined
98+
} catch (_) {
99+
parsedBody = undefined
100+
}
101+
const details = parsedBody ? JSON.stringify(parsedBody) : (errorBodyText ? errorBodyText.substring(0, 1000) : '')
102+
const err = new Error(`HTTP ${response.status}: ${response.statusText}${details ? ` | Body: ${details}` : ''}`)
103+
// Attach status for retry logic
104+
// @ts-ignore
105+
err.status = response.status
106+
throw err
89107
}
90108

91109
// Check if response has content

apps/shared-backend/netlify/functions/github-stats-background.mts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,12 @@ export const handler: Handler = async (event) => {
250250
body: JSON.stringify({ success: true })
251251
}
252252
} catch (err: any) {
253-
console.error('github-stats-background error:', err?.message || err)
253+
const errorMessage = err?.message || String(err)
254+
const errorCode = err?.code || err?.status || undefined
255+
console.error('github-stats-background error:', errorMessage)
254256
return {
255257
statusCode: 500,
256-
body: JSON.stringify({ success: false, error: 'Internal Server Error' })
258+
body: JSON.stringify({ success: false, error: 'Internal Server Error', details: errorMessage, code: errorCode })
257259
}
258260
}
259261
}

0 commit comments

Comments
 (0)