refactor: find or fail (#30697)

This commit is contained in:
Jason Rasmussen 2026-08-11 09:27:35 -04:00 committed by GitHub
parent 9773d72428
commit 927b4d0ea2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 48 additions and 74 deletions

View file

@ -1,4 +1,4 @@
import { INestApplication } from '@nestjs/common';
import { BadRequestException, INestApplication } from '@nestjs/common';
import {
ApiBodyOptions,
DocumentBuilder,
@ -111,6 +111,15 @@ export const handlePromiseError = <T>(promise: Promise<T>, logger: LoggingReposi
promise.catch((error: Error | any) => logger.error(`Promise error: ${error}`, error?.stack));
};
export const findOrFail = async <T>(find: () => Promise<T>, entity: string): Promise<NonNullable<T>> => {
const value = await find();
if (!value) {
throw new BadRequestException(`${entity} not found`);
}
return value;
};
export interface OpenGraphTags {
title: string;
description: string;