File tree Expand file tree Collapse file tree 1 file changed +25
-7
lines changed
packages/gitbook/src/routes Expand file tree Collapse file tree 1 file changed +25
-7
lines changed Original file line number Diff line number Diff line change 11import type { GitBookSiteContext } from '@/lib/context' ;
2- import { throwIfDataError } from '@/lib/data' ;
2+ import { getDataOrNull } from '@/lib/data' ;
33import { getMarkdownForPage } from '@/lib/markdownPage' ;
44
55/**
66 * Serve a markdown version of a page.
77 * Returns a 404 if the page is not found.
88 */
99export async function servePageMarkdown ( context : GitBookSiteContext , pagePath : string ) {
10- const result = await throwIfDataError ( getMarkdownForPage ( context , pagePath ) ) ;
10+ try {
11+ const result = await getDataOrNull ( getMarkdownForPage ( context , pagePath ) ) ;
12+ if ( ! result ) {
13+ return new Response ( 'Page not found' , {
14+ status : 404 ,
15+ headers : {
16+ 'Content-Type' : 'text/plain; charset=utf-8' ,
17+ } ,
18+ } ) ;
19+ }
1120
12- return new Response ( result , {
13- headers : {
14- 'Content-Type' : 'text/markdown; charset=utf-8' ,
15- } ,
16- } ) ;
21+ return new Response ( result , {
22+ headers : {
23+ 'Content-Type' : 'text/markdown; charset=utf-8' ,
24+ } ,
25+ } ) ;
26+ } catch ( error ) {
27+ console . error ( 'Error serving markdown page:' , error ) ;
28+ return new Response ( 'Internal Server Error' , {
29+ status : 500 ,
30+ headers : {
31+ 'Content-Type' : 'text/plain; charset=utf-8' ,
32+ } ,
33+ } ) ;
34+ }
1735}
You can’t perform that action at this time.
0 commit comments