@@ -4,7 +4,7 @@ import { cache } from "hono/cache"
44import { cors } from "hono/cors"
55import { HTTPException } from "hono/http-exception"
66
7- import { fetchJSONData } from "./lib/fetch"
7+ import { fetchJSONData , NotFoundError } from "./lib/fetch"
88import { createMcpServer } from "./lib/mcp"
99import { renderFromJSON } from "./lib/render"
1010import { generateAppleDocUrl , isValidAppleDocUrl , normalizeDocumentationPath } from "./lib/url"
@@ -112,7 +112,10 @@ This service only works with Apple Developer documentation URLs:
112112 )
113113 }
114114
115- return c . text ( markdown , 200 , { ...headers , "Content-Type" : "text/markdown; charset=utf-8" } )
115+ return c . text ( markdown , 200 , {
116+ ...headers ,
117+ "Content-Type" : "text/markdown; charset=utf-8" ,
118+ } )
116119} )
117120
118121// Catch-all route for any other requests - returns 404
@@ -140,6 +143,42 @@ app.onError((err, c) => {
140143 return err . getResponse ( )
141144 }
142145
146+ if ( err instanceof NotFoundError ) {
147+ const accept = c . req . header ( "Accept" )
148+ if ( accept ?. includes ( "application/json" ) ) {
149+ return c . json (
150+ {
151+ error : "Documentation not found" ,
152+ message : "The requested Apple Developer documentation page does not exist." ,
153+ } ,
154+ 404 ,
155+ )
156+ }
157+
158+ return c . text (
159+ `# Not Found
160+
161+ The requested Apple Developer documentation page does not exist.
162+
163+ ## What you can try:
164+
165+ 1. **Check the URL** - Make sure the path is correct
166+ 2. **Browse from a parent page** - Try starting from a higher-level documentation page
167+ 3. **Search Apple Developer Documentation** - Use Apple's official search
168+
169+ ## Examples of valid URLs:
170+
171+ - [Swift Documentation](https://sosumi.ai/documentation/swift)
172+ - [SwiftUI Documentation](https://sosumi.ai/documentation/swiftui)
173+ - [UIKit Documentation](https://sosumi.ai/documentation/uikit)
174+
175+ ---
176+ *[sosumi.ai](https://sosumi.ai) - Making Apple docs AI-readable*` ,
177+ 404 ,
178+ { "Content-Type" : "text/markdown; charset=utf-8" } ,
179+ )
180+ }
181+
143182 // Handle unexpected errors
144183 const accept = c . req . header ( "Accept" )
145184 if ( accept ?. includes ( "application/json" ) ) {
0 commit comments