Add a timeout option to HttpClientRequest
Type
- [ ] Refactor
- [x] Feature
- [ ] Bug Fix
- [ ] Optimization
- [ ] Documentation Update
Description
Adds a timeout option to HttpClientRequest, which results in a Transport RequestError if it's exceeded. I've erred on adding to the request rather than having it alongside to cater for cases where the client has been composed.
I'm sure that some of the implementation could be improved. 😄
Related
- Thread https://discord.com/channels/795981131316985866/1359836164005302392
- Related Issue #
- Closes #
🦋 Changeset detected
Latest commit: 06917f30d74b84fb23579ac21d406576aa281487
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 26 packages
| Name | Type |
|---|---|
| @effect/platform | Minor |
| @effect/cli | Major |
| @effect/cluster | Major |
| @effect/experimental | Major |
| @effect/platform-browser | Major |
| @effect/platform-bun | Major |
| @effect/platform-node-shared | Major |
| @effect/platform-node | Major |
| @effect/rpc | Major |
| @effect/sql-clickhouse | Major |
| @effect/sql-d1 | Major |
| @effect/sql-libsql | Major |
| @effect/sql-mssql | Major |
| @effect/sql-mysql2 | Major |
| @effect/sql-pg | Major |
| @effect/sql-sqlite-bun | Major |
| @effect/sql-sqlite-node | Major |
| @effect/sql | Major |
| @effect/ai | Major |
| @effect/ai-anthropic | Major |
| @effect/ai-openai | Major |
| @effect/sql-sqlite-do | Major |
| @effect/sql-sqlite-react-native | Major |
| @effect/sql-sqlite-wasm | Major |
| @effect/sql-drizzle | Major |
| @effect/sql-kysely | Major |
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
why not using plain Effect.timeout?
I'm looking to turn these into RequestErrors, which you can't (easily) with Effect.timeout*.
As mentioned in https://discord.com/channels/795981131316985866/1359836164005302392/1360164805025206322, composing the HttpClient with one that times out instead with an API like:
HttpClient.get('http://example.com/'),
HttpClient.withTimeout('1 second'),
Effect.andThen(...)
would work too.
You can add timeouts with customs errors like this:
Effect.gen(function*() {
const client = (yield* HttpClient.HttpClient).pipe(
HttpClient.transform((effect, request) =>
Effect.timeoutFail(effect, {
duration: 1000,
onTimeout: () => new Error(`${request.method} ${request.url} timed out`)
})
)
)
})