3
3
import _ from 'lodash' ;
4
4
import { useCallback , useEffect , useMemo , useRef } from 'react' ;
5
5
import {
6
- Callback , Dict , Falsy , getPrefixUrl , pendingPromise , useStateMounted , wait , buildUrlQueryString , Jsonify ,
6
+ Callback , Dict , Falsy , getPrefixUrl , pendingPromise , useStateMounted , wait , buildUrlQueryString , Jsonify , formatTime
7
7
} from '.'
8
8
import { BetterEventEmitter } from '../src/events'
9
9
@@ -41,6 +41,7 @@ export function apiCall<T=any>(cmd: string, params?: Dict, options: ApiCallOptio
41
41
console . debug ( 'API TIMEOUT' , cmd , params ?? '' )
42
42
} , ms )
43
43
const asRest = options . restUri
44
+ const started = new Date
44
45
// rebuilding the whole url makes it resistant to url-with-credentials
45
46
return Object . assign ( fetch ( `${ location . origin } ${ getPrefixUrl ( ) } ${ asRest || ( API_URL + cmd ) } ` , {
46
47
method : asRest ? cmd : ( options . method || 'POST' ) ,
@@ -54,7 +55,7 @@ export function apiCall<T=any>(cmd: string, params?: Dict, options: ApiCallOptio
54
55
try { data = options . skipParse ? body : JSON . parse ( body ) }
55
56
catch { data = body }
56
57
if ( ! options ?. skipLog )
57
- console . debug ( res . ok ? 'API' : 'API FAILED' , cmd , params ?? '' , '>>' , data )
58
+ console . debug ( res . ok ? 'API' : 'API FAILED' , cmd , params ?? '' , '>>' , data , { started : formatTime ( started ) , duration : ( Date . now ( ) - + started ) } )
58
59
await options . onResponse ?.( res , data )
59
60
if ( ! res . ok )
60
61
throw new ApiError ( res . status , data === body ? body : `Failed API ${ cmd } : ${ res . statusText } ` , data )
0 commit comments