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

refactor: simplify FetchrError and fix Error inheritance #352

Merged
merged 5 commits into from
Jan 18, 2022

Conversation

pablopalacios
Copy link
Contributor

After migrating from xhr to native fetch, many cases inside FetchrError were not reachable anymore. I didn't refactor it back that time since the code was super hard to understand and we didn't have functional tests to see the real consequences of updating it. But now it was a breeze.

Hopefully, FetchrError class is easier to understand now. I also briefly document it in the README and, as you can see, the data inside the error could be better and simplified. But it would introduce some breaking changes that I would postpone for V1 now.

I confirm that this contribution is made under the terms of the license found in the root directory of this repository's source tree and that I have the authority necessary to make this contribution on behalf of its copyright owner.

It's possible to remove it since native fetch always return a string
if we have a response and since we only have an error when we have no
response.
It's possible to do that since we will always have a bad status code.
It was necessary to create a error class in the server since there are
tests shared test code between server and client that can only work
with one class of error.
response,
responseBody
);
return response.text().then(function (body) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is body an error here? should we call it error instead?

Copy link
Contributor Author

@pablopalacios pablopalacios Jan 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean an Error instance or that the body contains an error message? Well, it's a string and it might contain some error message yes.
But I think it makes sense what you said, however, I think renaming to err could be misleading since, normally, err points to an Error instance. It gets more awkward since just a few lines below, we have another err name, and that one is a true error.
So I think renaming to message could be a good option (since this is the name of FetchrError param as well). What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

message makes sense to me

}

FetchrError.prototype = Object.create(Error.prototype);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not make it a proper class?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep es5 compatibility. I will transform it as soon as we move to TS, but for now, I think it's better to keep es5 syntax compatibility.

Copy link
Contributor

@redonkulus redonkulus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@redonkulus redonkulus merged commit 34295de into yahoo:master Jan 18, 2022
@pablopalacios pablopalacios deleted the refactor-error branch January 18, 2022 21:59
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

Successfully merging this pull request may close these issues.

2 participants