mirror of
https://github.com/Zakkaus/doona.git
synced 2026-12-05 08:00:59 +00:00
A JSON GET that comes back as an empty 2xx body, or gets no response at all, is sent once more after 300 ms. A second failure is reported with attempts: 2. Timeouts, caller aborts, error statuses, POSTs and the SSE streams are not retried, and GETs never enter the refusal loop. API errors now record the method, the path and query, and the Content-Type, Content-Length, Transfer-Encoding, Content-Encoding and Server response headers. The copied diagnostics add an attempts line and a headers line to each entry.
17 lines
528 B
TypeScript
17 lines
528 B
TypeScript
export function pause(ms: number, signal?: AbortSignal): Promise<void> {
|
|
signal?.throwIfAborted();
|
|
return new Promise((resolve, reject) => {
|
|
const abort = () => {
|
|
clearTimeout(timer);
|
|
reject(signal?.reason);
|
|
};
|
|
const timer = setTimeout(() => {
|
|
signal?.removeEventListener('abort', abort);
|
|
resolve();
|
|
}, ms);
|
|
signal?.addEventListener('abort', abort, {once: true});
|
|
});
|
|
}
|
|
|
|
export const wait = (seconds: number, signal?: AbortSignal) => pause(Math.max(1, seconds) * 1000, signal);
|