3
3
LoaderFunction ,
4
4
MetaFunction ,
5
5
Outlet ,
6
- redirect ,
6
+ redirect , ThrownResponse , useCatch ,
7
7
useLoaderData ,
8
8
useLocation ,
9
9
useParams ,
@@ -62,19 +62,17 @@ export const loader: LoaderFunction = async ({ params, request }) => {
62
62
} ) ;
63
63
64
64
if ( ! jsonResponse . ok ) {
65
- console . log (
66
- `Failed to fetch ${ doc . url } : ${ jsonResponse . status } (${ jsonResponse . statusText } )`
67
- ) ;
65
+ const jsonResponseText = await jsonResponse . text ( ) ;
66
+ const error = `Failed to fetch ${ doc . url } . HTTP status : ${ jsonResponse . status } (${ jsonResponseText } })` ;
67
+ console . error ( error ) ;
68
68
69
- throw new Response ( jsonResponse . statusText , {
69
+ throw new Response ( error , {
70
70
status : jsonResponse . status ,
71
71
} ) ;
72
72
}
73
73
74
74
const json = await jsonResponse . json ( ) ;
75
75
76
- console . log ( `Fetched ${ doc . url } with json, returning...` ) ;
77
-
78
76
return {
79
77
doc,
80
78
json,
@@ -166,7 +164,7 @@ export const meta: MetaFunction = ({
166
164
} ) => {
167
165
let title = "JSON Hero" ;
168
166
169
- if ( data ) {
167
+ if ( data ?. doc ?. title ) {
170
168
title += ` - ${ data . doc . title } ` ;
171
169
}
172
170
@@ -250,7 +248,10 @@ export default function JsonDocumentRoute() {
250
248
}
251
249
252
250
export function CatchBoundary ( ) {
251
+ const error = useCatch ( ) ;
253
252
const params = useParams ( ) ;
253
+ console . log ( "error" , error )
254
+
254
255
return (
255
256
< div className = "flex items-center justify-center w-screen h-screen bg-[rgb(56,52,139)]" >
256
257
< div className = "w-2/3" >
@@ -259,15 +260,19 @@ export function CatchBoundary() {
259
260
< Logo />
260
261
</ div >
261
262
< PageNotFoundTitle className = "text-center leading-tight" >
262
- 404
263
+ { error . status }
263
264
</ PageNotFoundTitle >
264
265
</ div >
265
266
< div className = "text-center leading-snug text-white" >
266
267
< ExtraLargeTitle className = "text-slate-200 mb-8" >
267
268
< b > Sorry</ b > ! Something went wrong...
268
269
</ ExtraLargeTitle >
269
270
< SmallSubtitle className = "text-slate-200 mb-8" >
270
- We couldn't find the page < b > 'https://jsonhero.io/j/{ params . id } </ b > '
271
+ { error . data || (
272
+ error . status === 404
273
+ ? < > We couldn't find the page < b > 'https://jsonhero.io/j/{ params . id } '</ b > </ >
274
+ : "Unknown error occurred."
275
+ ) }
271
276
</ SmallSubtitle >
272
277
< a
273
278
href = "/"
0 commit comments