File tree Expand file tree Collapse file tree 5 files changed +9
-28
lines changed
Expand file tree Collapse file tree 5 files changed +9
-28
lines changed Original file line number Diff line number Diff line change @@ -128,11 +128,7 @@ collections
128128 })
129129 .then (accountBalance => console .log ({ accountBalance }))
130130 .catch (error => {
131- if (error .response ) {
132- return console .log (error .response .data , error .response .config );
133- }
134-
135- return console .log (error .message );
131+ console .log (error);
136132 });
137133```
138134
@@ -211,10 +207,6 @@ disbursements
211207 })
212208 .then (accountBalance => console .log ({ accountBalance }))
213209 .catch (error => {
214- if (error .response ) {
215- console .log (error .response .data , error .response .config );
216- }
217-
218- console .log (error .message );
210+ console .log (error);
219211 });
220212```
Original file line number Diff line number Diff line change @@ -37,9 +37,5 @@ disbursements
3737 } )
3838 . then ( accountBalance => console . log ( { accountBalance } ) )
3939 . catch ( error => {
40- if ( error . response ) {
41- console . log ( error . response . data , error . response . config ) ;
42- }
43-
44- console . log ( error . message ) ;
40+ console . log ( error ) ;
4541 } ) ;
Original file line number Diff line number Diff line change 2525 },
2626 "keywords" : [
2727 " MTN" ,
28- " Mobile Money" ,
28+ " Mobile" ,
29+ " Money" ,
2930 " Momo" ,
3031 " TypeScript" ,
3132 " NodeJS"
3738 "dependencies" : {
3839 "axios" : " ^0.18.0" ,
3940 "commander" : " ^2.19.0" ,
40- "moment" : " ^2.22.2" ,
4141 "uuid" : " ^3.3.2"
4242 },
4343 "devDependencies" : {
Original file line number Diff line number Diff line change 11import { AxiosInstance } from "axios" ;
2- import moment from "moment" ;
32
43import { createClient } from "./client" ;
54
@@ -14,7 +13,7 @@ export type Authorizer = (
1413
1514interface OAuthCredentials {
1615 accessToken : string ;
17- expires : Date ;
16+ expires : number ;
1817}
1918
2019export function createTokenRefresher (
@@ -27,11 +26,10 @@ export function createTokenRefresher(
2726 return authorize ( config )
2827 . then ( ( accessToken : AccessToken ) => {
2928 const { access_token, expires_in } : AccessToken = accessToken ;
29+ const expires : number = Date . now ( ) + expires_in * 1000 - 60000 ;
3030 return {
3131 accessToken : access_token ,
32- expires : moment ( )
33- . add ( expires_in , "seconds" )
34- . toDate ( )
32+ expires
3533 } ;
3634 } )
3735 . then ( freshCredentials => {
@@ -83,5 +81,5 @@ function isExpired(credentials: OAuthCredentials): boolean {
8381 return true ;
8482 }
8583
86- return moment ( ) . isAfter ( credentials . expires ) ;
84+ return Date . now ( ) > credentials . expires ;
8785}
You can’t perform that action at this time.
0 commit comments