Skip to content

Commit 314a5d7

Browse files
committed
dx: more debug data
1 parent 9e30528 commit 314a5d7

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

shared/api.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import _ from 'lodash';
44
import { useCallback, useEffect, useMemo, useRef } from 'react';
55
import {
6-
Callback, Dict, Falsy, getPrefixUrl, pendingPromise, useStateMounted, wait, buildUrlQueryString, Jsonify,
6+
Callback, Dict, Falsy, getPrefixUrl, pendingPromise, useStateMounted, wait, buildUrlQueryString, Jsonify, formatTime
77
} from '.'
88
import { BetterEventEmitter } from '../src/events'
99

@@ -41,6 +41,7 @@ export function apiCall<T=any>(cmd: string, params?: Dict, options: ApiCallOptio
4141
console.debug('API TIMEOUT', cmd, params??'')
4242
}, ms)
4343
const asRest = options.restUri
44+
const started = new Date
4445
// rebuilding the whole url makes it resistant to url-with-credentials
4546
return Object.assign(fetch(`${location.origin}${getPrefixUrl()}${asRest || (API_URL + cmd)}`, {
4647
method: asRest ? cmd : (options.method || 'POST'),
@@ -54,7 +55,7 @@ export function apiCall<T=any>(cmd: string, params?: Dict, options: ApiCallOptio
5455
try { data = options.skipParse ? body : JSON.parse(body) }
5556
catch { data = body }
5657
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) })
5859
await options.onResponse?.(res, data)
5960
if (!res.ok)
6061
throw new ApiError(res.status, data === body ? body : `Failed API ${cmd}: ${res.statusText}`, data)

0 commit comments

Comments
 (0)