Comments (7)
I would recommend to make a full example of what it's currently not working.
Even better: open a PR to fix it!
from fastify-circuit-breaker.
Ok this is my example :
const Fastify = require('fastify')
const fastify = Fastify()
// that Handler helped me for catch CircuitOpenError but it can't catch the TimeoutError
fastify.setErrorHandler(function (_error, request, reply) {
console.log('================^^^^^====================')
console.log(_error)
console.log('=========================================')
return reply.send({ ERRRROR: 404 })
})
fastify.register(require('fastify-circuit-breaker'), {
threshold: 2,
timeout: 3000,
resetTimeout: 30000,
// maby if add arg like taht helpful :/
TimeoutError: (req, reply) => {
return reply.send({ TimeoutError: 404 })
}
})
fastify.register(function (instance, opts, next) {
instance.route({
method: 'GET',
url: '/*',
schema: {
querystring: {
error: { type: 'boolean' },
delay: { type: 'number' }
}
},
preHandler: instance.circuitBreaker(),
handler: async function (req, reply) {
setTimeout(() => {
reply.send(
req.query.error ? { error: 404 } : { hello: 'world' }
)
}, req.query.delay || 0)
}
})
next()
})
fastify.listen(3000, err => {
if (err) throw err
console.log('Server listening at http://localhost:3000')
})
the error i can't catch him at Object.onSend (\node_modules\fastify-circuit-breaker\index.js:74:19)
return next(new TimeoutError())
:/
from fastify-circuit-breaker.
What would you like to do with that error?
from fastify-circuit-breaker.
What would you like to do with that error?
i need catch the error from [setErrorHandler] and then make a Custom response.
===================================================
i find this solution
replace return next(new TimeoutError())
to return next(null, JSON.stringify({Error:"timeout"}))
in [\node_modules\fastify-circuit-breaker\index.js:74:19]
and its work but i don't know if this perfect way.
.
.
.
.
.
.
.
i am sorry for my language i know little english and google translate help me ^_^
from fastify-circuit-breaker.
I think this could be a feature to add: need to add an option onTimeout
that must return the body to sent. This is need to maintain the circuit breaker patter
This feature is like this one fastify/fastify-compress#88 if you would like to give it a shot! 💪🏻
from fastify-circuit-breaker.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
from fastify-circuit-breaker.
think this could be a feature to add: need to add an option
onTimeout
that must return the body to sent. This is need to maintain the circuit breaker patter
Hi - I came across this issue and would like to contribute this feature. In my application, I want to respond with a 504
on a TimeoutError
. Having both onTimeout
and onCircuitOpen
would probably make sense.
An alternative would be to add status code options for both timeoutError and circuitOpenError. Thoughts?
from fastify-circuit-breaker.
Related Issues (7)
- index.d.ts lost onCircuitOpen and onTimeout in FastifyCircuitBreakerOptions HOT 1
- fastify-circuit-breaker caused fastify instance crash ? HOT 4
- Feature Request - Percentage based error thresholds HOT 3
- circuitBreaker decorator is not available when used outside of a plugin HOT 1
- Coverage 100%
- Optionally breaking the circuit without having to wait for the route handler to finish HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastify-circuit-breaker.