Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return error using custom fetch #382

Closed
villenams opened this issue Sep 1, 2022 · 1 comment
Closed

Return error using custom fetch #382

villenams opened this issue Sep 1, 2022 · 1 comment

Comments

@villenams
Copy link

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?

error_with_custom_fetch

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);
  });
}
});

@jasonkuhrt
Copy link
Member

File uploads were removed in #501

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants