Skip to content

Commit

Permalink
render simple preprint loading error
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane98c committed Feb 25, 2025
1 parent a8cd09c commit 6182cb0
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,34 @@ const Home = async ({ searchParams }: HomeProps) => {
if (subject) {
url += `&subject=${subject}`
}
const res = await fetchWithAlerting(url, { next: { revalidate: 180 } })
const preprints = await res.json()
const results = preprints.results || []

let results = []
let nextPage = null
let totalCount = 0
let error = false

try {
const res = await fetchWithAlerting(url, { next: { revalidate: 180 } })
const preprints = await res.json()
results = preprints.results || []
nextPage = preprints.next
totalCount = preprints.count
} catch (err) {
error = true
}

return (
<LandingPage>
<PreprintsView
preprints={results}
nextPage={preprints.next}
totalCount={preprints.count}
preprintsPerPage={preprintsPerPage}
/>
{error ? (
<div style={{ textAlign: 'center' }}>Unable to load preprints.</div>
) : (
<PreprintsView
preprints={results}
nextPage={nextPage}
totalCount={totalCount}
preprintsPerPage={preprintsPerPage}
/>
)}
</LandingPage>
)
}
Expand Down

0 comments on commit 6182cb0

Please sign in to comment.