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
19
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.1.0 to 3.2.0

4

package.json
{
"name": "@fastify/circuit-breaker",
"version": "3.1.0",
"version": "3.2.0",
"description": "A low overhead circuit breaker for your routes",

@@ -34,3 +34,3 @@ "main": "index.js",

"tap": "^16.0.0",
"tsd": "^0.24.1"
"tsd": "^0.25.0"
},

@@ -37,0 +37,0 @@ "dependencies": {

@@ -7,2 +7,3 @@ import {

} from "fastify";
import { Stream } from "node:stream";

@@ -34,2 +35,3 @@ declare module "fastify" {

threshold?: number;
/**

@@ -46,2 +48,34 @@ * The maximum number of milliseconds you can wait before return a `TimeoutError`.

resetTimeout?: number;
/**
* Gets called when the circuit is `open` due to timeouts.
* It can modify the reply and return a `string` | `Buffer` | `Stream` |
* `Error` payload. If an `Error` is thrown it will be routed to your error
* handler.
*/
onTimeout?: (request: FastifyRequest, reply: FastifyReply) => void | string | Buffer | Stream | Error | Promise<void | string | Buffer | Stream | Error>;
/**
*
* @default 'Timeout'
*/
timeoutErrorMessage?: string;
/**
* Gets called when the circuit is `open` due to errors.
* It can modify the reply and return a `string` | `Buffer` | `Stream`
* payload. If an `Error` is thrown it will be routed to your error handler.
*/
onCircuitOpen?: (request: FastifyRequest, reply: FastifyReply) => void | string | Buffer | Stream | Promise<void | string | Buffer | Stream>;
/**
* @default 'Circuit open'
*/
circuitOpenErrorMessage?: string;
/**
* The amount of cached requests.
* @default 500
*/
cache?: number;
};

@@ -48,0 +82,0 @@ export const fastifyCircuitBreaker: FastifyCircuitBreaker

@@ -1,2 +0,3 @@

import fastify from "fastify";
import fastify, { FastifyReply, FastifyRequest } from "fastify";
import { expectType } from "tsd";
import FastifyCircuitBreaker, { FastifyCircuitBreakerOptions } from "..";

@@ -29,3 +30,57 @@

},
(req, reply) => {}
(req, reply) => { }
);
app.register(FastifyCircuitBreaker, { timeoutErrorMessage: 'Timeon' });
app.register(FastifyCircuitBreaker, {
onTimeout: async (req, reply) => {
expectType<FastifyRequest>(req)
expectType<FastifyReply>(reply)
const statusCode = await Promise.resolve(504)
reply.statusCode = statusCode
throw new Error('timed out')
}
});
app.register(FastifyCircuitBreaker, {
onTimeout: (req, reply) => {
expectType<FastifyRequest>(req)
expectType<FastifyReply>(reply)
reply.statusCode = 504
return 'timed out'
}
});
app.register(FastifyCircuitBreaker, {
onTimeout: async (req, reply) => {
expectType<FastifyRequest>(req)
expectType<FastifyReply>(reply)
reply.statusCode = 504
return 'timed out'
}
});
app.register(FastifyCircuitBreaker, { circuitOpenErrorMessage: 'circus open' });
app.register(FastifyCircuitBreaker, {
onCircuitOpen: async (req, reply) => {
expectType<FastifyRequest>(req)
expectType<FastifyReply>(reply)
const statusCode = await Promise.resolve(504)
reply.statusCode = statusCode
throw new Error('circuit open')
}
});
app.register(FastifyCircuitBreaker, {
onCircuitOpen: (req, reply) => {
expectType<FastifyRequest>(req)
expectType<FastifyReply>(reply)
reply.statusCode = 504
return 'circuit open'
}
});
app.register(FastifyCircuitBreaker, {
onCircuitOpen: async (req, reply) => {
expectType<FastifyRequest>(req)
expectType<FastifyReply>(reply)
reply.statusCode = 504
return 'circuit open'
}
});
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