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 1
1
import type { GitBookSiteContext } from '@/lib/context' ;
2
- import { throwIfDataError } from '@/lib/data' ;
2
+ import { getDataOrNull } from '@/lib/data' ;
3
3
import { getMarkdownForPage } from '@/lib/markdownPage' ;
4
4
5
5
/**
6
6
* Serve a markdown version of a page.
7
7
* Returns a 404 if the page is not found.
8
8
*/
9
9
export 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
+ }
11
20
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
+ }
17
35
}
You can’t perform that action at this time.
0 commit comments