33 LoaderFunction ,
44 MetaFunction ,
55 Outlet ,
6- redirect ,
6+ redirect , ThrownResponse , useCatch ,
77 useLoaderData ,
88 useLocation ,
99 useParams ,
@@ -57,19 +57,17 @@ export const loader: LoaderFunction = async ({ params, request }) => {
5757 const jsonResponse = await safeFetch ( doc . url ) ;
5858
5959 if ( ! jsonResponse . ok ) {
60- console . log (
61- `Failed to fetch ${ doc . url } : ${ jsonResponse . status } (${ jsonResponse . statusText } )`
62- ) ;
60+ const jsonResponseText = await jsonResponse . text ( ) ;
61+ const error = `Failed to fetch ${ doc . url } . HTTP status : ${ jsonResponse . status } (${ jsonResponseText } })` ;
62+ console . error ( error ) ;
6363
64- throw new Response ( jsonResponse . statusText , {
64+ throw new Response ( error , {
6565 status : jsonResponse . status ,
6666 } ) ;
6767 }
6868
6969 const json = await jsonResponse . json ( ) ;
7070
71- console . log ( `Fetched ${ doc . url } with json, returning...` ) ;
72-
7371 return {
7472 doc,
7573 json,
@@ -245,7 +243,10 @@ export default function JsonDocumentRoute() {
245243}
246244
247245export function CatchBoundary ( ) {
246+ const error = useCatch ( ) ;
248247 const params = useParams ( ) ;
248+ console . log ( "error" , error )
249+
249250 return (
250251 < div className = "flex items-center justify-center w-screen h-screen bg-[rgb(56,52,139)]" >
251252 < div className = "w-2/3" >
@@ -254,15 +255,19 @@ export function CatchBoundary() {
254255 < Logo />
255256 </ div >
256257 < PageNotFoundTitle className = "text-center leading-tight" >
257- 404
258+ { error . status }
258259 </ PageNotFoundTitle >
259260 </ div >
260261 < div className = "text-center leading-snug text-white" >
261262 < ExtraLargeTitle className = "text-slate-200 mb-8" >
262263 < b > Sorry</ b > ! Something went wrong...
263264 </ ExtraLargeTitle >
264265 < SmallSubtitle className = "text-slate-200 mb-8" >
265- We couldn't find the page < b > 'https://jsonhero.io/j/{ params . id } </ b > '
266+ { error . data || (
267+ error . status === 404
268+ ? < > We couldn't find the page < b > 'https://jsonhero.io/j/{ params . id } '</ b > </ >
269+ : "Unknown error occurred."
270+ ) }
266271 </ SmallSubtitle >
267272 < a
268273 href = "/"
0 commit comments