New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@fastify/circuit-breaker

Package Overview
Dependencies
Maintainers
0
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fastify/circuit-breaker - npm Package Compare versions

Comparing version 3.2.0 to 4.0.0-pre.fv5.1

.gitattributes

4

index.js
'use strict'
const fp = require('fastify-plugin')
const lru = require('tiny-lru').lru
const { FifoObject } = require('toad-cache')
const createError = require('@fastify/error')

@@ -20,3 +20,3 @@

const onTimeout = opts.onTimeout
const cache = lru(opts.cache || 500)
const cache = new FifoObject(opts.cache || 500)

@@ -23,0 +23,0 @@ let routeId = 0

{
"name": "@fastify/circuit-breaker",
"version": "3.2.0",
"version": "4.0.0-pre.fv5.1",
"description": "A low overhead circuit breaker for your routes",

@@ -29,13 +29,13 @@ "main": "index.js",

"devDependencies": {
"@fastify/pre-commit": "^2.0.2",
"@types/node": "^18.0.0",
"fastify": "^4.0.0-rc.2",
"standard": "^17.0.0",
"tap": "^16.0.0",
"tsd": "^0.25.0"
"@fastify/pre-commit": "^2.1.0",
"@types/node": "^20.11.30",
"fastify": "^5.0.0-alpha.2",
"standard": "^17.1.0",
"tap": "^20.0.1",
"tsd": "^0.31.1"
},
"dependencies": {
"@fastify/error": "^3.0.0",
"fastify-plugin": "^4.0.0",
"tiny-lru": "^10.0.0"
"@fastify/error": "^4.0.0",
"fastify-plugin": "^5.0.0-pre.fv5.1",
"toad-cache": "^3.7.0"
},

@@ -42,0 +42,0 @@ "bugs": {

@@ -713,1 +713,107 @@ 'use strict'

})
test('Should not throw error if no options is passed', t => {
t.plan(3)
const fastify = Fastify()
const fastify2 = Fastify()
const fastify3 = Fastify()
t.equal(circuitBreaker(fastify, undefined, () => {}), undefined)
t.equal(circuitBreaker(fastify2, null, () => {}), undefined)
t.equal(circuitBreaker(fastify3, {}, () => {}), undefined)
})
test('Should throw error on route status open and circuit open', t => {
t.plan(5)
const fastify = Fastify()
fastify.register(circuitBreaker, {
threshold: 1,
timeout: 1000,
resetTimeout: 1500,
onCircuitOpen: async (req, reply) => {
reply.statusCode = 500
return JSON.stringify({ err: 'custom error' })
}
})
fastify.after(() => {
fastify.get('/', { preHandler: fastify.circuitBreaker() }, (req, reply) => {
t.equal(typeof req._cbTime, 'number')
setTimeout(() => {
reply.send(new Error('kaboom'))
}, 0)
})
})
fastify.inject('/?error=true', (err, res) => {
t.error(err)
})
setTimeout(() => {
fastify.inject('/?error=false', (err, res) => {
t.equal(null, err)
t.equal(res.statusCode, 500)
t.same(res.json(), { err: 'custom error' })
})
}, 1000)
})
test('Should throw error on route status half open and circuit open', t => {
t.plan(15)
const fastify = Fastify()
fastify.register(circuitBreaker, {
threshold: 2,
timeout: 1000,
resetTimeout: 500,
onCircuitOpen: async (req, reply) => {
reply.statusCode = 500
return JSON.stringify({ err: 'custom error' })
}
})
fastify.after(() => {
opts.preHandler = fastify.circuitBreaker()
fastify.get('/', opts, (req, reply) => {
t.equal(typeof req._cbTime, 'number')
setTimeout(() => {
reply.send(new Error('kaboom'))
}, 0)
})
})
fastify.inject('/?error=true', (err, res) => {
t.error(err)
t.equal(res.statusCode, 500)
t.same({
error: 'Internal Server Error',
message: 'kaboom',
statusCode: 500
}, JSON.parse(res.payload))
})
fastify.inject('/?error=true', (err, res) => {
t.error(err)
t.equal(res.statusCode, 500)
t.same(res.json(), { err: 'custom error' })
})
setTimeout(() => {
fastify.inject('/?error=true', (err, res) => {
t.error(err)
t.equal(res.statusCode, 500)
t.same({
error: 'Internal Server Error',
message: 'kaboom',
statusCode: 500
}, JSON.parse(res.payload))
})
fastify.inject('/?error=true', (err, res) => {
t.equal(null, err)
t.equal(res.statusCode, 500)
t.same(res.json(), { err: 'custom error' })
})
}, 1000)
})

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc