Skip to content

V2#3

Merged
smithamax merged 3 commits intomasterfrom
feature/v2
Apr 4, 2025
Merged

V2#3
smithamax merged 3 commits intomasterfrom
feature/v2

Conversation

@smithamax
Copy link
Copy Markdown
Member

@smithamax smithamax commented Apr 3, 2025

I've re-done v2 and published as v2.0.0-rc.3, to see the old v2.0.0-rc.2 look or the tag or other/v2.0.0-rc.2 branch

rc.2 seemed a little overbuilt when it came to errors etc. Has a lot going on for metrics
to try and make http_client_request_stage_duration_seconds work, but didn't really do anything.

On top of all that, it didn't even remove got from package.json

So I started again with a simpler approach

The main breaking change is that we switched from got to native node fetch
for the underlying HTTP client. This means that the API is now more aligned with
the native fetch API.

  • The Response object is now from native fetch and not got
  • Options are now native fetch options not got options
  • Errors are now native fetch errors not got errors
  • default _handlerResponse now returns the parsed body of the response
  • Timout is no longer an option, pass a signal on the fetch options instead
  • No longer supports the retry option, wrap your call to request in a retry loop instead
  • No longer supports the http_client_request_stage_duration_seconds metric

Any project upgrading will have to to a fair bit of work, but it'll mostly be in the _handlerResponse and _handlerError functions

Big breaking changes

Uses fetch instead of got
@smithamax smithamax self-assigned this Apr 3, 2025
@smithamax smithamax changed the title I've re-done v2 and published as v2.0.0-rc.3, to see the old v2.0.0-rc.2 look or the tag or other/v2.0.0-rc.2 branch V2 Apr 3, 2025
@smithamax smithamax requested a review from denwilliams April 3, 2025 07:24
Comment thread README.md Outdated
- Options are now native `fetch` options not `got` options
- Errors are now native `fetch` errors not `got` errors
- default `_handlerResponse` now returns the parsed body of the response
- Timout is no longer an option, pass a `signal` on the fetch options instead
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Worth having an example of how to do this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah probably, thinking of adding context support in the future so you can do it via that too

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

also timout -> timeout

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

🙃

Comment thread README.md
- Timout is no longer an option, pass a `signal` on the fetch options instead
- No longer supports the `retry` option, wrap your call to `request` in a retry
loop instead
- No longer supports the `http_client_request_stage_duration_seconds` metric
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What did this metric provide?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's pretty nice, it shows what http spent time on, see the last graph here

https://grafana.loke.com.au/d/000000050/http-client-requests?orgId=1&from=now-3h&to=now&timezone=browser&var-environment=000000008&var-job=$__all&var-base=https:%2F%2Fapi.pwnedpasswords.com%2F

But fetch doesn't give us the individual timings so can't do it

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i don't think ive ever scrolled down to see that graph

Comment thread README.md
- Errors are now native `fetch` errors not `got` errors
- default `_handlerResponse` now returns the parsed body of the response
- Timout is no longer an option, pass a `signal` on the fetch options instead
- No longer supports the `retry` option, wrap your call to `request` in a retry
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not worth building this in to the lib? Or having a best practices example?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't think we use it enough to bother building it in, and it's pretty easy for the caller to just wrap in a retry loop.

If we build it in we have to add logic around response codes and method types in a generic way. The caller can just figure out this themself

Comment thread README.md Outdated

- The Response object is now from native `fetch` and not `got`
- Options are now native `fetch` options not `got` options
- Errors are now native `fetch` errors not `got` errors
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are there some common error cases we should document?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looking the deliverect PR I think a big one would be statusCode -> status

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

and no more .body or .headers, use .response instead

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Mostly because all the error conditions are harder to hit when testing

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think the example _handlerError does a pretty good job showing what the basic pattern should be

@smithamax smithamax requested a review from denwilliams April 4, 2025 00:46
@smithamax smithamax merged commit d3bac51 into master Apr 4, 2025
4 checks passed
@smithamax smithamax deleted the feature/v2 branch April 4, 2025 03:09
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