diff --git a/web/src/routes/explore/+page.server.js b/web/src/routes/explore/+page.server.js index 6c361e4c..24ca2abf 100644 --- a/web/src/routes/explore/+page.server.js +++ b/web/src/routes/explore/+page.server.js @@ -1,5 +1,6 @@ import { env } from '$env/dynamic/private'; import { error } from '@sveltejs/kit'; +import checkApiStatus from '$lib/checkApiStatus.server.js'; export async function load({ cookies }) { try { @@ -51,6 +52,15 @@ export async function load({ cookies }) { if (apiRes?.data?.recentStudysets?.length >= 0) { recentStudysets = apiRes.data.recentStudysets; } + + let apiStatus; + /* if there's no data, check qzfr-api status */ + if (!(featuredStudysets?.length >= 1 || recentStudysets?.length >= 1)) { + apiStatus = await checkApiStatus({ + authCookie: cookies.get("auth"), + API_URL: env.API_URL + }) + } return { featuredStudysets: featuredStudysets, recentStudysets: recentStudysets, @@ -58,12 +68,34 @@ export async function load({ cookies }) { authedUser: authedUser, header: { activePage: "explore" - } + }, + graphQLErrors: apiRes?.errors, + apiStatus: apiStatus } } catch (err) { console.error(err); - error(404, { - message: "Not Found" + let apiStatus = await checkApiStatus({ + authCookie: cookies.get("auth"), + API_URL: env.API_URL }) + if (!(apiStatus?.apiUp) || (apiStatus?.apiResponseErrorNotJSON)) { + return { + authed: false, + header: { + activePage: "explore" + }, + pageServerJSError: false, + apiStatus: apiStatus + } + } else { + return { + authed: false, + header: { + activePage: "explore" + }, + pageServerJSError: true, + apiStatus: apiStatus + } + } } } diff --git a/web/src/routes/explore/+page.svelte b/web/src/routes/explore/+page.svelte index 416e867c..17ea886a 100644 --- a/web/src/routes/explore/+page.svelte +++ b/web/src/routes/explore/+page.svelte @@ -11,7 +11,7 @@
- {#if (data.featuredStudysets.length >= 1) } + {#if (data.featuredStudysets?.length >= 1) }

Featured Studysets

{#each data.featuredStudysets as featuredStudyset } @@ -31,7 +31,7 @@ {/each}
{/if} - {#if (data.recentStudysets.length >= 1) } + {#if (data.recentStudysets?.length >= 1) }

Recently Created or Updated

{#each data.recentStudysets as studyset } @@ -51,6 +51,44 @@ {/each}
{/if} + {#if data?.pageServerJSError} +
+

Oh no!!

+

There was an error in the code that loads this page.

+

If you're a developer/contributor, check web/src/routes/explore/+page.server.js

+

You probably don't need to check API Status, because this error is from qzfr-web, but have the link anyway i guess

+
+ {:else if !(data.featuredStudysets?.length >= 1 || data.recentStudysets?.length >= 1) } + {#if data?.apiStatus?.apiUp} + {#if data?.apiStatus?.dbConnectionUp} + {#if data?.graphQLErrors?.length >= 1} +
+

Oh no!!

+

Quizfreely's API sent us an error via GraphQL.

+

That usually means the API is running, but something is wrong in qzfr-web's query or qzfr-api's resolver (i don't know which one while i'm writing this error message)

+
+ {:else} +
+ There are no public studysets to show here.
+ Everything loaded correctly tho (i think) +
+ {/if} + {:else} +
+

Oh no!!

+

We couldn't load anything because our API's database connection is down.

+

Quizfreely's API is running correctly and everything, but the DB isn't :(

+

Check API Status for more info

+
+ {/if} + {:else} +
+

Oh no!!

+

We couldn't load anything because Quizfreely's API is down.

+

Check API Status for more info

+
+ {/if} + {/if}