@blackflux/axios
Version:
Axios Wrapper
23 lines (21 loc) • 535 B
JavaScript
import redactAndThrow from './redact-and-throw.js';
const wrap = (v) => {
if (typeof v !== 'function') {
return v;
}
if (Object.getOwnPropertyDescriptor(v, 'prototype')?.writable === false) {
return v;
}
const fn = (...kwargs) => {
const r = v(...kwargs);
if (typeof r === 'function') {
return Object.assign(wrap(r), r);
}
if (typeof r?.then === 'function' && typeof r?.catch === 'function') {
return r.catch(redactAndThrow);
}
return r;
};
return fn;
};
export default wrap;