Giter Club home page Giter Club logo

Comments (7)

mcollina avatar mcollina commented on May 20, 2024 1

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.

iibrahem avatar iibrahem commented on May 20, 2024

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.

mcollina avatar mcollina commented on May 20, 2024

What would you like to do with that error?

from fastify-circuit-breaker.

iibrahem avatar iibrahem commented on May 20, 2024

What would you like to do with that error?

i need catch the error from [setErrorHandler] and then make a Custom response.

Untitled

===================================================

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.

Eomm avatar Eomm commented on May 20, 2024

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.

stale avatar stale commented on May 20, 2024

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.

ryhinchey avatar ryhinchey commented on May 20, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.