3
3
LoaderFunction ,
4
4
MetaFunction ,
5
5
Outlet ,
6
- redirect ,
6
+ redirect , ThrownResponse , useCatch ,
7
7
useLoaderData ,
8
8
useLocation ,
9
9
useParams ,
@@ -57,19 +57,17 @@ export const loader: LoaderFunction = async ({ params, request }) => {
57
57
const jsonResponse = await safeFetch ( doc . url ) ;
58
58
59
59
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 ) ;
63
63
64
- throw new Response ( jsonResponse . statusText , {
64
+ throw new Response ( error , {
65
65
status : jsonResponse . status ,
66
66
} ) ;
67
67
}
68
68
69
69
const json = await jsonResponse . json ( ) ;
70
70
71
- console . log ( `Fetched ${ doc . url } with json, returning...` ) ;
72
-
73
71
return {
74
72
doc,
75
73
json,
@@ -245,7 +243,10 @@ export default function JsonDocumentRoute() {
245
243
}
246
244
247
245
export function CatchBoundary ( ) {
246
+ const error = useCatch ( ) ;
248
247
const params = useParams ( ) ;
248
+ console . log ( "error" , error )
249
+
249
250
return (
250
251
< div className = "flex items-center justify-center w-screen h-screen bg-[rgb(56,52,139)]" >
251
252
< div className = "w-2/3" >
@@ -254,15 +255,19 @@ export function CatchBoundary() {
254
255
< Logo />
255
256
</ div >
256
257
< PageNotFoundTitle className = "text-center leading-tight" >
257
- 404
258
+ { error . status }
258
259
</ PageNotFoundTitle >
259
260
</ div >
260
261
< div className = "text-center leading-snug text-white" >
261
262
< ExtraLargeTitle className = "text-slate-200 mb-8" >
262
263
< b > Sorry</ b > ! Something went wrong...
263
264
</ ExtraLargeTitle >
264
265
< 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
+ ) }
266
271
</ SmallSubtitle >
267
272
< a
268
273
href = "/"
0 commit comments