Skip to content

Commit

Permalink
fix(backend): crash on unhandled promise rejections
Browse files Browse the repository at this point in the history
  • Loading branch information
stonith404 committed Apr 4, 2024
1 parent c0a245e commit 1da4fee
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion backend/src/auth/auth.service.ts
Expand Up @@ -99,7 +99,7 @@ export class AuthService {
include: { resetPasswordToken: true },
});

if (!user) throw new BadRequestException("User not found");
if (!user) return;

// Delete old reset password token
if (user.resetPasswordToken) {
Expand Down
12 changes: 10 additions & 2 deletions backend/src/main.ts
@@ -1,20 +1,25 @@
import { ClassSerializerInterceptor, ValidationPipe } from "@nestjs/common";
import {
ClassSerializerInterceptor,
Logger,
ValidationPipe,
} from "@nestjs/common";
import { NestFactory, Reflector } from "@nestjs/core";
import { NestExpressApplication } from "@nestjs/platform-express";
import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger";
import * as bodyParser from "body-parser";
import * as cookieParser from "cookie-parser";
import * as fs from "fs";
import { AppModule } from "./app.module";
import { DATA_DIRECTORY } from "./constants";
import { ConfigService } from "./config/config.service";
import { DATA_DIRECTORY } from "./constants";

async function bootstrap() {
const app = await NestFactory.create<NestExpressApplication>(AppModule);
app.useGlobalPipes(new ValidationPipe({ whitelist: true }));
app.useGlobalInterceptors(new ClassSerializerInterceptor(app.get(Reflector)));

const config = app.get<ConfigService>(ConfigService);

app.use(
bodyParser.raw({
type: "application/octet-stream",
Expand Down Expand Up @@ -42,5 +47,8 @@ async function bootstrap() {
}

await app.listen(parseInt(process.env.PORT) || 8080);

const logger = new Logger("UnhandledAsyncError");
process.on("unhandledRejection", (e) => logger.error(e));
}
bootstrap();

0 comments on commit 1da4fee

Please sign in to comment.