@@ -15,6 +15,16 @@ import * as pulls from './operations/pulls.js';
15
15
import * as branches from './operations/branches.js' ;
16
16
import * as search from './operations/search.js' ;
17
17
import * as commits from './operations/commits.js' ;
18
+ import {
19
+ GitHubError ,
20
+ GitHubValidationError ,
21
+ GitHubResourceNotFoundError ,
22
+ GitHubAuthenticationError ,
23
+ GitHubPermissionError ,
24
+ GitHubRateLimitError ,
25
+ GitHubConflictError ,
26
+ isGitHubError ,
27
+ } from './common/errors.js' ;
18
28
19
29
const server = new Server (
20
30
{
@@ -28,6 +38,29 @@ const server = new Server(
28
38
}
29
39
) ;
30
40
41
+ function formatGitHubError ( error : GitHubError ) : string {
42
+ let message = `GitHub API Error: ${ error . message } ` ;
43
+
44
+ if ( error instanceof GitHubValidationError ) {
45
+ message = `Validation Error: ${ error . message } ` ;
46
+ if ( error . response ) {
47
+ message += `\nDetails: ${ JSON . stringify ( error . response ) } ` ;
48
+ }
49
+ } else if ( error instanceof GitHubResourceNotFoundError ) {
50
+ message = `Not Found: ${ error . message } ` ;
51
+ } else if ( error instanceof GitHubAuthenticationError ) {
52
+ message = `Authentication Failed: ${ error . message } ` ;
53
+ } else if ( error instanceof GitHubPermissionError ) {
54
+ message = `Permission Denied: ${ error . message } ` ;
55
+ } else if ( error instanceof GitHubRateLimitError ) {
56
+ message = `Rate Limit Exceeded: ${ error . message } \nResets at: ${ error . resetAt . toISOString ( ) } ` ;
57
+ } else if ( error instanceof GitHubConflictError ) {
58
+ message = `Conflict: ${ error . message } ` ;
59
+ }
60
+
61
+ return message ;
62
+ }
63
+
31
64
server . setRequestHandler ( ListToolsRequestSchema , async ( ) => {
32
65
return {
33
66
tools : [
@@ -298,7 +331,10 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
298
331
}
299
332
} catch ( error ) {
300
333
if ( error instanceof z . ZodError ) {
301
- throw new Error ( `ZodErrors: ${ JSON . stringify ( error . errors ) } ` ) ;
334
+ throw new Error ( `Invalid input: ${ JSON . stringify ( error . errors ) } ` ) ;
335
+ }
336
+ if ( isGitHubError ( error ) ) {
337
+ throw new Error ( formatGitHubError ( error ) ) ;
302
338
}
303
339
throw error ;
304
340
}
0 commit comments