File tree Expand file tree Collapse file tree 1 file changed +15
-8
lines changed
Expand file tree Collapse file tree 1 file changed +15
-8
lines changed Original file line number Diff line number Diff line change @@ -40,16 +40,23 @@ $(document).ready(function() {
4040
4141 async function fetchCommits ( ) {
4242 const response = await fetch ( `https://api.github.com/repos/${ github_username } /${ github_repository } /commits` ) ;
43- const commits = await response . json ( ) ;
4443
45- const commitDate = formatDate ( commits [ 0 ] . commit . author . date ) ;
44+ let displayText
4645
47- // you could also display commit message
48- const commitMessage = commits [ 0 ] . commit . message ;
49- const cuttoff = 100 ;
50- const commitMessageDisplay = commitMessage . length > cuttoff ? commitMessage . substring ( 0 , cuttoff ) + "..." : commitMessage ;
51-
52- const displayText = `Last updated: ${ commitDate } ` ;
46+ if ( response . ok ) {
47+ const commits = await response . json ( ) ;
48+
49+ const commitDate = formatDate ( commits [ 0 ] . commit . author . date ) ;
50+
51+ // you could also display commit message
52+ const commitMessage = commits [ 0 ] . commit . message ;
53+ const cuttoff = 100 ;
54+ const commitMessageDisplay = commitMessage . length > cuttoff ? commitMessage . substring ( 0 , cuttoff ) + "..." : commitMessage ;
55+
56+ displayText = `Last updated: ${ commitDate } ` ;
57+ } else {
58+ displayText = `Last updated: recently` ;
59+ }
5360
5461 document . getElementById ( 'updateMessage' ) . innerHTML = displayText
5562 }
You can’t perform that action at this time.
0 commit comments