File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import fetch , { FetchError } from "node-fetch" ;
12import { GitHubNotifications } from "../exp/github-notification" ;
23import { GitHubUser } from "../exp/github-user" ;
34import { Query } from "../play/notify" ;
4- import fetch from "node-fetch" ;
55
66export const notificationQuery : Query = {
77 async fetchNotification ( {
@@ -11,14 +11,21 @@ export const notificationQuery: Query = {
1111 const base64 = Buffer . from ( `${ userName } :${ notificationToken } ` ) . toString (
1212 "base64" ,
1313 ) ;
14- const rawRes = await fetch ( "https://api.github.com/notifications" , {
15- headers : {
16- Authorization : `Basic ${ base64 } ` ,
17- } ,
18- } ) ;
19- if ( ! rawRes . ok ) {
20- throw new Error ( "fail to fetch notifications" ) ;
14+ try {
15+ const rawRes = await fetch ( "https://api.github.com/notifications" , {
16+ headers : {
17+ Authorization : `Basic ${ base64 } ` ,
18+ } ,
19+ } ) ;
20+ if ( ! rawRes . ok ) {
21+ return [ ] ;
22+ }
23+ return [ ...( ( await rawRes . json ( ) ) as unknown [ ] ) ] as GitHubNotifications ;
24+ } catch ( err : unknown ) {
25+ if ( err instanceof FetchError ) {
26+ return [ ] ;
27+ }
28+ throw err ;
2129 }
22- return [ ...( ( await rawRes . json ( ) ) as unknown [ ] ) ] as GitHubNotifications ;
2330 } ,
2431} ;
You can’t perform that action at this time.
0 commit comments