@samitouri / QOSami-HFS / commits / 314a5d76

dx: more debug data

Massimo Melina committed Jun 21, 2025 at 11:49 UTC 314a5d76826eff6916bf1950a33b7b767534ff91
1 file changed +3 -2
shared/api.ts
+3 -2
@@ -3,7 +3,7 @@
3 import _ from 'lodash';
4 import { useCallback, useEffect, useMemo, useRef } from 'react';
5 import {
6 - Callback, Dict, Falsy, getPrefixUrl, pendingPromise, useStateMounted, wait, buildUrlQueryString, Jsonify,
6 + Callback, Dict, Falsy, getPrefixUrl, pendingPromise, useStateMounted, wait, buildUrlQueryString, Jsonify, formatTime
7 } from '.'
8 import { BetterEventEmitter } from '../src/events'
9
@@ -41,6 +41,7 @@ export function apiCall<T=any>(cmd: string, params?: Dict, options: ApiCallOptio
41 console.debug('API TIMEOUT', cmd, params??'')
42 }, ms)
43 const asRest = options.restUri
44 + const started = new Date
45 // rebuilding the whole url makes it resistant to url-with-credentials
46 return Object.assign(fetch(`${location.origin}${getPrefixUrl()}${asRest || (API_URL + cmd)}`, {
47 method: asRest ? cmd : (options.method || 'POST'),
@@ -54,7 +55,7 @@ export function apiCall<T=any>(cmd: string, params?: Dict, options: ApiCallOptio
55 try { data = options.skipParse ? body : JSON.parse(body) }
56 catch { data = body }
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) })
59 await options.onResponse?.(res, data)
60 if (!res.ok)
61 throw new ApiError(res.status, data === body ? body : `Failed API ${cmd}: ${res.statusText}`, data)