Fixes some broken services from this library

This commit is contained in:
CJ
2024-01-09 17:31:13 -06:00
committed by GitHub
parent 47d066ee4d
commit 71c96b0428

View File

@@ -1,5 +1,28 @@
const stashListener = new EventTarget();
const {
fetch: originalFetch
} = window;
window.fetch = async (...args) => {
let [resource, config] = args;
// request interceptor here
const response = await originalFetch(resource, config);
// response interceptor here
const contentType = response.headers.get("content-type");
if (contentType && contentType.indexOf("application/json") !== -1 && resource.endsWith('/graphql')) {
try {
const data = await response.clone().json();
stashListener.dispatchEvent(new CustomEvent('response', {
'detail': data
}));
} catch (e) {
}
}
return response;
};
class Logger {
constructor(enabled) {
this.enabled = enabled;