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

Unhandled exception in request() method of class Client #761

Open
dentakoy opened this issue Nov 29, 2022 · 0 comments
Open

Unhandled exception in request() method of class Client #761

dentakoy opened this issue Nov 29, 2022 · 0 comments

Comments

@dentakoy
Copy link

dentakoy commented Nov 29, 2022

Hello!
I find unhandled exception in request() method of class Client.
File src/client.ts line 33

  request(command: string, body?: any) {
    const url = `${this.address}/api/${command}`;
    let init;
    if (body) {
      init = {
        method: 'POST',
        headers: {
          Accept: 'application/json',
          'Content-Type': 'application/json'
        },
        body: JSON.stringify(body)
      };
    }
    return new Promise((resolve, reject) => {
      fetch(url, init)
        .then((res) => {
          if (res.ok) return resolve(res.json());
          throw res;
        })
        // line with unhandled exception: .catch((e) => e.json().then((json) => reject(json)));
        // my fix:
        .catch((e) => {
          e.json()
            .then((json)  => reject(json))
            .catch((e)    => reject(e))
        });
    });
  }
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

1 participant