Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

caught-exception

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

caught-exception

Error handler and http status code and validate request

  • 0.0.35
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
14
increased by250%
Maintainers
1
Weekly downloads
 
Created
Source

caught-exception

Create Exception Filter

src/config/caught-exception/caught-exception.filter.ts
import { Catch, HttpException, Injectable } from '@nestjs/common';
import { HttpExceptionFilter } from 'caught-exception';
import dataDogTracer from './config/datadog/tracer';

@Injectable()
@Catch(HttpException)
export class HttpExceptionFilterInject extends HttpExceptionFilter {
  dataDogTracer = dataDogTracer;
}

Global Caught Exception Filter

src/main.js
require('./config/datadog/tracer');
import { HttpExceptionFilterInject } from './src/config/caught-exception/caught-exception.filter.ts';

async function bootstrap() {
  // const app = await NestFactory.create(RootModule, {
  app.useGlobalFilters(new HttpExceptionFilterInject());
  // ...
}

DataDog file

src/config/datadog/trace.js
import tracer from 'dd-trace';
const dataDogTracer = tracer.init();
export default dataDogTracer;

Intercept all axios Require/Response in development

src/root.module.js
import axios from 'axios';
import dataDogTracer from './src/config/datadog/tracer';
require('caught-exception/dist/common/api/http-request-global.axios')({
  axios,
  dataDogTracer,
});

Provider HttpExceptionFilterInject on RootModule

src/root.module.js
import { HttpExceptionFilterInject } from './caught-exception';
import { APP_FILTER } from '@nestjs/core';

@Module({
  // imports: [],
  // controllers: [],
  providers: [
    {
      provide: APP_FILTER,
      useClass: HttpExceptionFilterInject,
    },
  ],
});

Caught controllers Require

src/root.module.js
import { LoggerMiddlewareToModule } from './caught-exception';
// replace this:
// export class RootModule {};
// to:
export class RootModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    consumer.apply(LoggerMiddlewareToModule).forRoutes('*');
  }
}

Environments

DD_LOGS_CONFIG_CONTAINER_COLLECT_ALL= true
DD_LOGS_ENABLED= true
DD_LOGS_INJECTION= true
DD_PROCESS_CONFIG_ENABLED= true
DD_PROFILING_ENABLE= true
DD_TRACE_ANALYTICS_ENABLED= false
DD_TRACE_ENABLED= true
DD_TRACE_HEADER_TAGS= Host:origin,Referer:referer,x-forwarded-for:x-forwarded-for
DD_VERSION= 4.14.0
// intercept
CATCH_EXCEPTION_TRACE_ROUTES_RULES= { "intercept": { } }
// Intercept: /auth/login 
// Don't exclude: /path/document/example 
CATCH_EXCEPTION_TRACE_ROUTES_RULES= { "intercept": { "include": ["login"], "exclude": ["document"] } }
// Axios intercept prod
CATCH_EXCEPTION_TRACE_ROUTES_RULES= { "intercept": { "production": true } }

FAQs

Package last updated on 22 Sep 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