File tree Expand file tree Collapse file tree 1 file changed +21
-4
lines changed
Expand file tree Collapse file tree 1 file changed +21
-4
lines changed Original file line number Diff line number Diff line change 11import { fetchProps } from '../utils/propsData/fetch'
2+ import { createJsonResponse } from '../utils/apiHelpers'
23
34export const prerender = false
45
56export async function GET ( { request } : { request : Request } ) {
67 const url = new URL ( request . url )
7- const props = await fetchProps ( url )
88
99 const components = url . searchParams . get ( 'components' )
10- const componentsArray = components ?. split ( ',' )
11- const propsData = componentsArray ?. map ( ( component ) => props [ component ] )
10+ if ( ! components ) {
11+ return createJsonResponse (
12+ { error : 'components query parameter is required' } ,
13+ 400 ,
14+ )
15+ }
1216
13- return new Response ( JSON . stringify ( propsData ) )
17+ try {
18+ const props = await fetchProps ( url )
19+ const propsData = components
20+ . split ( ',' )
21+ . map ( ( component ) => props [ component . trim ( ) ] )
22+
23+ return createJsonResponse ( propsData )
24+ } catch ( error ) {
25+ const details = error instanceof Error ? error . message : String ( error )
26+ return createJsonResponse (
27+ { error : 'Failed to load props data' , details } ,
28+ 500 ,
29+ )
30+ }
1431}
You can’t perform that action at this time.
0 commit comments