ucdavis / PolicyWonk

Chat with a UC Policy Expert
2 stars 1 forks source link

error handling #27

Open laholstege opened 4 months ago

laholstege commented 4 months ago
laholstege commented 2 months ago

when testing error boundaries on the client in dev, the bottom left red error overlay will still show up. this won't happen in production

laholstege commented 1 month ago

100

updated pattern: pages no longer check session, and i assume the middleware will handle that. instead, each interaction with the database checks session before doing anything, and returns a status for known errors (not found, not authorized, etc). each page handles what to do on those statuses, and any server errors are caught by the higher level error.tsx page. chatHistory is the only other place outside a page where we are fetching data, so it does a try/catch, since we don't want a server error in the sidebar to crash the whole page. if we didn't catch it here, it would result in an error in the layout and next would render global-error.tsx

see: https://github.com/vercel/next.js/discussions/49426 for discussion on error handling

currently, the next js docs only address how to handle errors from server actions from within a form, but we use standalone actions so it doesn't really apply https://rc.nextjs.org/docs/app/building-your-application/routing/error-handling