-
Notifications
You must be signed in to change notification settings - Fork 310
Closed
Description
I am using a custom fetch function to monitor the upload of a file, everything runs fine, but at the end of the process it always returns an error message.
Maybe I should implement my custom fetch in a different way?
const graphql = newGraphqlClient({
fetch: (
url,
options: {
body?: FormData;
method?: string;
headers?: Record<string, string>;
} = {}
) => {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.open(options.method || "POST", url);
for (const o in options.headers || {}) {
xhr.setRequestHeader(o, options.headers[o]);
}
xhr.onload = (event) => {
return resolve({
ok: true,
text: () => Promise.resolve(event.target),
json: () => Promise.resolve(event.target)
});
};
xhr.onerror = reject;
if (xhr.upload) {
xhr.upload.onprogress = (event) => {
console.log(event.loaded / event.total) * 100);
};
}
xhr.send(options.body);
});
}
});
manoj-makkuboy
Metadata
Metadata
Assignees
Labels
No labels