Skip to content
This repository has been archived by the owner on Dec 20, 2020. It is now read-only.

Suggestion : warn about error handling #144

Open
Flyaku opened this issue Aug 23, 2017 · 1 comment
Open

Suggestion : warn about error handling #144

Flyaku opened this issue Aug 23, 2017 · 1 comment

Comments

@Flyaku
Copy link

Flyaku commented Aug 23, 2017

Hi,

I think it would be a good idea to warn developers that functions called in .then will throw errors in .catch, and errors in functions called in .catch will have to be catched by a try...catch block.

It might not be an issue for developers with a good understanding of JS, but it can be quite confusing at first when you got swallowed errors.

Maybe just by updating the examples with something like that :

.then(function (xhr, response) {
    if (typeof validationCallback === 'function') {
        validationCallback(response);
    }
})
.catch(function (error, xhr, response) {
    console.error(error);

    try {
        if (typeof errorCallback === 'function') {
            errorCallback(error, xhr, response);
        }
    } catch (error) {
        console.error(error);
    }
});

--
PS : Since it's my first message on this repo, I'd like to thank you and the community for the good work on the library, I'm using qwest a lot and I really appreciate it. 👍

@pyrsmk
Copy link
Owner

pyrsmk commented Aug 29, 2017

Indeed, even if it's a behavior from the Promises spec, it can be confusing at first. Thanks for reporting it!

As I'm a bit busy lately, can you handle this ticket by adding a chapter/note somewhere in the README and pushing a PR? If your examples are clear, I would be glad to approve it ASAP ;)

PS : I'm glad that qwest's matching your needs! Stay tuned for the upcoming v5, I will do a complete rewrite because qwest's structure is obsolete and has several bugs or bad designs

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

No branches or pull requests

2 participants