Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Is there way to access Sentry directly in app.ts #88

Open
sedhuait opened this issue Jul 1, 2022 · 0 comments
Open

Question: Is there way to access Sentry directly in app.ts #88

sedhuait opened this issue Jul 1, 2022 · 0 comments

Comments

@sedhuait
Copy link

sedhuait commented Jul 1, 2022

Hey there,
Is there a way to access Sentry in app.ts to capture uncaught exceptions. please find the sample code below

//app.ts

import {
  INestApplication,
  NestApplicationOptions,
  ValidationPipe,
  BadRequestException,
  ValidationError,
  RequestMethod,
} from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { ExpressAdapter } from '@nestjs/platform-express';
import express from 'express';

import { AppModule } from './app.module';
import { ConfigService, isLocal } from './platform';

const ERROR_EXIT_CODE = 1;

/* istanbul ignore next */
process
  .on('unhandledRejection', reason => {
    // eslint-disable-next-line no-console
    console.error(reason);
    Sentry.captureException(reason);
    process.exit(ERROR_EXIT_CODE);
  })
  .on('uncaughtException', err => {
    // eslint-disable-next-line no-console
    console.error(err);
    Sentry.captureException(err);
    process.exit(ERROR_EXIT_CODE);
  });

export default async function createApp(): Promise<INestApplication> {
  const expressServer = express();
  const httpAdapter = new ExpressAdapter(expressServer);
  const options: NestApplicationOptions = { logger: false, bodyParser: false };
  const app: INestApplication = await NestFactory.create(AppModule, httpAdapter, options);
  const config = app.get(ConfigService);

  app.enableCors();
  
  );

  return app;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant