Skip to content

Commit 793c038

Browse files
Update query.js
Signed-off-by: Suyash Pathak <suyashp271@gmail.com>
1 parent 0472076 commit 793c038

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

  • lib/node_modules/@stdlib/_tools/github/star-repo/lib

lib/node_modules/@stdlib/_tools/github/star-repo/lib/query.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ function query( slug, options, clbk ) {
6262
* @returns {void}
6363
*/
6464
function done( error, response ) {
65+
var resetDate;
66+
var resetISO;
6567
var info;
6668
if ( arguments.length === 1 ) {
6769
debug( 'No available rate limit information.' );
@@ -73,7 +75,20 @@ function query( slug, options, clbk ) {
7375
info = ratelimit( response.headers );
7476
debug( 'Rate limit: %d', info.limit );
7577
debug( 'Rate limit remaining: %d', info.remaining );
76-
debug( 'Rate limit reset: %s', (new Date( info.reset*1000 )).toISOString() );
78+
79+
// Guard against invalid or missing reset values which would throw a RangeError when calling toISOString:
80+
resetISO = 'n/a';
81+
if (
82+
info &&
83+
typeof info.reset === 'number' &&
84+
isFinite( info.reset )
85+
) {
86+
resetDate = new Date( info.reset*1000 );
87+
if ( !isNaN( resetDate.getTime() ) ) {
88+
resetISO = resetDate.toISOString();
89+
}
90+
}
91+
debug( 'Rate limit reset: %s', resetISO );
7792

7893
if ( error ) {
7994
return clbk( error, info );

0 commit comments

Comments
 (0)