File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ async function fetcher(GH_TOKEN, URL) {
2020 const response = await UrlFetchApp . fetch ( pageUrl , options ) ;
2121
2222 if ( response . getResponseCode ( ) !== 200 ) {
23- throw new Error ( `API request failed with status ${ response . getResponseCode ( ) } : ${ response . getContentText ( ) } ` ) ;
23+ return handleHttpStatus ( response . getResponseCode ( ) ) ;
2424 }
2525
2626 const data = JSON . parse ( response . getContentText ( ) ) ;
Original file line number Diff line number Diff line change 1+ /**
2+ * Handles HTTP status codes returned from a GitHub API request.
3+ *
4+ * @param {number } statusCode - The HTTP status code.
5+ * @returns {Object } An object containing `success` (boolean) and `message` properties.
6+ * @throws {Error } Throws an error if the status code is invalid or unexpected.
7+ */
8+ function handleHttpStatus ( statusCode ) {
9+ switch ( statusCode ) {
10+ case 204 :
11+ return { success : true , message : 'Operation successfully completed.' } ;
12+ case 304 :
13+ return { success : false , message : 'Not modified.' } ;
14+ case 401 :
15+ return { success : false , message : 'Requires authentication.' } ;
16+ case 403 :
17+ return { success : false , message : 'Forbidden.' } ;
18+ case 404 :
19+ return { success : false , message : 'Resource not found.' } ;
20+ default :
21+ throw new Error ( `Invalid HTTP status code: ${ statusCode } ` ) ;
22+ }
23+ }
You can’t perform that action at this time.
0 commit comments