From c2a6cb86399dfd06023bc63ea62efeafa349a40c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=93=8D=BC?= <143974574+xojw@users.noreply.github.com> Date: Fri, 6 Jun 2025 19:06:46 -0500 Subject: [PATCH] uh --- public/assets/js/$.js | 51 ++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/public/assets/js/$.js b/public/assets/js/$.js index 0c4e2130..2b7e0f30 100644 --- a/public/assets/js/$.js +++ b/public/assets/js/$.js @@ -456,19 +456,44 @@ document.addEventListener('DOMContentLoaded', () => { }); (async () => { - try { - const res = await fetch('/api/latest-commit'); - console.log('Fetching latest commit from API:', res); - if (!res.ok) { - throw new Error(`HTTP error! status: ${res.status}`); + const commitElement = document.getElementById('lastest-commit'); + + try { + const res = await fetch('/api/latest-commit'); + + console.log('Fetching latest commit from API:', res); + + if (!res.ok) { + const remaining = res.headers.get('X-RateLimit-Remaining'); + const reset = res.headers.get('X-RateLimit-Reset'); + + console.warn(`Status: ${res.status}`); + if (remaining !== null) { + console.warn(`Rate limit remaining: ${remaining}`); + if (Number(remaining) === 0) { + const resetDate = reset ? new Date(Number(reset) * 1000) : 'unknown'; + throw new Error(`Rate limit exceeded. Try again at ${resetDate}`); + } } - const { updates } = await res.json(); - const u = updates[0]; - const commitUrl = `https://github.com/xojw/waves/commit/${u.sha}`; - document.getElementById('lastest-commit').innerHTML = - ` ${u.sha}`; - } catch { - document.getElementById('lastest-commit').textContent = - 'Failed to load lastest commit'; + + if (res.status === 403) { + throw new Error('403 Forbidden — possibly rate limited or blocked.'); + } + + throw new Error(`HTTP error! status: ${res.status}`); } + + const { updates } = await res.json(); + const u = updates[0]; + const commitUrl = `https://github.com/xojw/waves/commit/${u.sha}`; + + commitElement.innerHTML = ` + + ${u.sha} + `; + } catch (err) { + console.error('Failed to fetch latest commit:', err.message || err); + + commitElement.textContent = 'Failed to load latest commit'; + } })(); \ No newline at end of file