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

fetch should be in try-catch #13

Closed
iegik opened this issue Mar 25, 2018 · 4 comments
Closed

fetch should be in try-catch #13

iegik opened this issue Mar 25, 2018 · 4 comments
Labels
bug Something isn't working

Comments

@iegik
Copy link

iegik commented Mar 25, 2018

fetch should be in try-catch because of possible error on request.
There is no try-catch on https://github.com/eventbrite/eventbrite-sdk-javascript/blob/master/src/request.ts#L42

export default (...args) => {
    try {
        return fetch(...args)
    } catch (e) {
        return Promise.reject(e);
    }
};

or

export default async (...args) => {
    try {
        return await fetch(...args)
    } catch (e) {
        return e;
    }
};

https://gist.github.com/iegik/3a69da2034156d52b858096ba3aa26f6

@benmvp
Copy link
Contributor

benmvp commented Mar 26, 2018

Thanks for the help!

So a timeout in the fetch call wouldn't reject the promise?

@iegik
Copy link
Author

iegik commented Mar 27, 2018

@benmvp Sorry, I can't reproduce for now, but in some cases I've got JS error on fetch execution. Maybe it was ReactNative 54 bug, I don't remember.
I did not find how to emulate "no response" error, but Timeout and Offline can catch in catch.

const addButton = (url, options) => {
    a = document.createElement('button');
    document.body.appendChild(a);
    a.innerText = [url, JSON.stringify(options)];
    a.onclick = e => {
        fetch(url, options).then(resp => {
          console.log('resp', resp)
        }).catch(e => {
          console.error('Catched error', e)
        })
    }
}
addButton('https://example.com'); // net::ERR_INTERNET_DISCONNECTED when Offline
addButton('https://example.com:81'); // net::ERR_CONNECTION_TIMED_OUT

@ryanwholey
Copy link
Contributor

@iegik thanks for clarifying! maybe we should close this issue until we can reproduce?

@benmvp
Copy link
Contributor

benmvp commented Mar 29, 2018

Yep, I think we should. We can always reopen if the issue arises

@BenAtEventbrite BenAtEventbrite added the bug Something isn't working label Mar 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants