OpenBeta / open-tacos

Rock climbing route catalog (openbeta.io)
https://openbeta.io
GNU Affero General Public License v3.0
110 stars 111 forks source link

fix(#1100): Gracefully handle runtime error for getArea query #1111

Closed melissapthai closed 3 months ago

melissapthai commented 3 months ago

What type of PR is this?(check all applicable)

Description

Currently, if you go to an area whose uuid doesn't exist in the database, it'll throw a server error (ex: https://openbeta.io/area/f92d68ca-1b6f-5bc7-8d1f-16b3961b3cce):

image

And if you go to an area with an invalid uuid, it'll throw a 404 (ex: https://openbeta.io/area/asdfasdf):

image

I believe this is occurring because of the way Apollo Server handles validation errors (like invalid uuids) vs resolver errors (area uuid doesn't exist in database).

What this PR achieves

This PR remediates this issue by wrapping the graphql query made in getArea in a try/catch. If the query errors out, return a null area. And when rendering the area page, return notFound() for a null area.

Screenshot 2024-03-19 at 9 08 20 PM

Since the AreaPageDataProps interface was changed to accommodate for the area being nullable, I had to update a number of other places in the code that use this:

export interface AreaPageDataProps {
  area: AreaType | null
  getAreaHistory: ChangesetType[]
}

Related Issues

Issue #1100

Notes

vercel[bot] commented 3 months ago

@melissapthai is attempting to deploy a commit to the openbeta-dev Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] commented 3 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
open-tacos ✅ Ready (Inspect) Visit Preview Mar 22, 2024 3:06pm
vnugent commented 3 months ago

@melissapthai the build is failing on Vercel.com. Does this link work for you?

https://vercel.com/openbeta-dev/open-tacos/AmGt7PPiKqKqwWL9aDTfREn8S7eR#L33

melissapthai commented 3 months ago

@vnugent that link works, but I get a 404 on https://vercel.com/openbeta-dev/open-tacos and https://vercel.com/openbeta-dev/

Also, I fixed the build issue and now it's green.

vnugent commented 3 months ago

@all-contributors add @melissapthai for code

allcontributors[bot] commented 3 months ago

@vnugent

I've put up a pull request to add @melissapthai! :tada: