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

@fuse-autotech/nest-timeout

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fuse-autotech/nest-timeout

This package enables to use a custom timeout alongside with the global timeout interceptor.

  • 2.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.1K
decreased by-39.51%
Maintainers
2
Weekly downloads
 
Created
Source

Fuse Logo Nest Logo

Timeout Interceptor for NestJS

Description

NestJS Timeout Interceptor repository. It enables setting up a global timeout for a NestJS application, which can be overridden by a Timeout Decorator for controller classes and methods specific timeouts. This gives the user more flexibility with a small amount of additional code. Method timeouts are preferred over class timeouts, which are preferred over global timeouts. Enjoy!

Installation

$ npm install @fuse-autotech/nest-timeout

Usage

Interceptor

Options:

  • defaultTimeout - Number of milliseconds after which the interceptor throws a RequestTimeoutException if no other timeout is defined for the endpoint
  • isEnabled - Determine if the interceptor is enabled. Defaults to true. Useful for debugging to avoid timeouts

import { Module } from "@nestjs/common";
import { APP_INTERCEPTOR } from "@nestjs/core";
import { TimeoutInterceptor } from "@fuse-autotech/nest-timeout";

@Module({
    imports: [],
    controllers: [],
    providers: [{
        provide: APP_INTERCEPTOR,
        useValue: new TimeoutInterceptor({ defaultTimeout: 10000 })
    }]
})
export class AppModule {}

@Timeout() Decorator

Can be used both on Controllers and Controller Methods:


import { Controller, Get, Param, Post } from '@nestjs/common';
import { Timeout } from '@fuse-autotech/nest-timeout';

@Controller('cats')
@Timeout(10000) // Applied for all methods unless decorated
export class CatsController {
    @Get()
    findAll(): string {
        return 'This action returns all cats';
    }
		
    @Get(':id') 
    @Timeout(30000) // Overrides controller timeout
    findOne(@Param('id') id: string ): string {
			return `This action returns a #${id} cat`;
		}

    @Post()
    @Timeout(0) // Disables timeout for the method
    create(): string {
        return 'This action adds a new cat';
    }
}

License

Nest timeout is MIT licensed.

FAQs

Package last updated on 10 Dec 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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