Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions src/properties/properties.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
UseGuards,
Res,
HttpStatus,
NotFoundException,
InternalServerErrorException,
} from '@nestjs/common';
import { PropertiesService } from './properties.service';
import { CreatePropertyDto, UpdatePropertyDto } from './dto/property.dto';
Expand Down Expand Up @@ -106,13 +108,19 @@ export class PropertiesController {

res.send(pdfBuffer);
} catch (error) {
if (error.message?.includes('not found')) {
res.status(HttpStatus.NOT_FOUND).send({ message: error.message });
return;
// Re-throw known NestJS HTTP exceptions so the global exception filter
// handles them correctly without leaking internal details.
if (error instanceof NotFoundException || error instanceof InternalServerErrorException) {
throw error;
}
res
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.send({ message: 'Failed to generate property report' });

// Remap Prisma "not found" errors to a safe NotFoundException.
if (error?.code === 'P2025' || error?.name === 'NotFoundError') {
throw new NotFoundException(`Property with id "${id}" was not found`);
}

// All other unexpected errors become a generic 500 with no internal detail.
throw new InternalServerErrorException('Failed to generate property report');
}
}

Expand Down
Loading