Skip to content

Errors 500 + are not propagated by the react client #6

New issue

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

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

Already on GitHub? # to your account

Open
Twathik opened this issue Mar 20, 2022 · 0 comments
Open

Errors 500 + are not propagated by the react client #6

Twathik opened this issue Mar 20, 2022 · 0 comments

Comments

@Twathik
Copy link

Twathik commented Mar 20, 2022

Hello

Errors 500 are not propagated by the client to be catched by the ui

private fetch = (input: globalThis.RequestInfo, init?: RequestInit): Promise<any> => {
    const key = input.toString();
    return new Promise<any>(async (resolve, reject) => {
      if (this.inflight[key]) {
        this.inflight[key].push({ resolve, reject });
        return;
      }
      this.inflight[key] = [{ resolve, reject }];
      try {
        const res = await fetch(input, init);
        const inflight = this.inflight[key];
        if (res.status === 200) {
          const json = await res.json();
          delete this.inflight[key];
          setTimeout(() => {
            inflight.forEach((cb) => cb.resolve(json));
          }, 0);
        }
        if (res.status >= 401 && res.status <= 499) {
          this.csrfToken = undefined;
          delete this.inflight[key];
          inflight.forEach((cb) => cb.reject('unauthorized'));
          this.fetchUser();
        }
      } catch (e: any) {
        const inflight = this.inflight[key];
        delete this.inflight[key];
        inflight.forEach((cb) => cb.reject(e));
      }
    });
  };

if we have a >= 500 error, it is not propagated (for exp when an api goes down) I have shut down my graphql api on purpoose, but the error is not catched

try {
      await createMessage({
        input: { ...values },
      });
      form.reset();
    } catch (err) {
      console.log({ err });
    }

The request failed as expected but no error was propagated due to the client implementation
I propose to throw an error if res. status is 500 + or to return an error response

Thnx

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

No branches or pull requests

1 participant