zidhuss / muscat-tech.org

All tech events in Muscat

Home Page:https://muscat-tech.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fix 404 when fetching events

DevAseel opened this issue · comments

Description

Currently, in the production environment, the application is returning a 404 error when attempting to fetch events for a month with no stored events (no JSON file). See the following screenshots:

Screenshot 2023-08-04 at 1 11 56 PM

Screenshot 2023-08-04 at 1 12 40 PM

Steps to resolve the issue:

  • Include a pre-check to only fetch existing json files.

Success Criteria

  • No 404 errors in the console window.

Looks like the page fetches the events for the currently selected month, and the next month. This should be an easy fix. Will try to work on a PR

@DevAseel It looks like this is the expected behavior from a browser. The fetch API that's being used catches the error successfully, but still logs it into the console as the promise is successful.

More info on this StackOverflow comment.

I wanted to give some context on this. This behavior, while it may seem like an error, is actually an intentional design choice 😅

To get around not having an API, we're serving the calendar event data as json files. We're only generating json files for months that have events.

When FullCalendar tries to fetch event data for a month, if there's no corresponding JSON file, it will receive a 404 error. This error is then handled by our code, and interpreted as "there are no events this month".

If you wanted to stop seeing 404s we'd need to have an API endpoint that accepts the month/year so it returns 200 and serves the correct file, or an empty array.

We're using Netlify for hosting so we could write a serverless function to do this. I'm open to someone implementing that but it's not a priority for me.

Seems fair and completely valid. Haven't messed with Netlify serverless functions, but if they're anything like Vercel or Lambda, should be easy to do.

Will look into this!

We're using Netlify for hosting so we could write a serverless function to do this. I'm open to someone implementing that but it's not a priority for me.

Seems like Netlify Functions don't persist any kind of data. So storing the event data somewhere would still be a concern.