I’m using the Weaviate TypeScript client library and want to implement a circuit breaker pattern. Instead of wrapping each individual function that calls weaviate.client, I’d like to intercept the requests at a lower level - possibly at the client/connection level.
My current approach looks something like this:
const weaviateClient = weaviate.client({
scheme: 'http',
host: 'localhost:8080',
});
// Currently I would need to wrap each function like this
const searchWithCircuitBreaker = circuitBreaker.wrap(async () => {
const result = await weaviateClient.graphql
.get()
.withClassName('Class')
.withFields('field1 field2')
.do();
return result;
});
Is there a way to intercept all requests at the client level?
For example:
- Intercepting the underlying HTTP client/requests
- Wrapping the client initialization
- Using some middleware functionality if available
- Any other approach that would allow implementing circuit breaker at a lower level
The goal is to have a single point where all requests go through the circuit breaker without having to wrap each individual function call.
Any suggestions on how to achieve this with the JS/TS client v2?
Thank you!