mirror of
https://github.com/immich-app/immich
synced 2026-08-29 13:15:45 +00:00
refactor: find or fail (#30697)
This commit is contained in:
parent
9773d72428
commit
927b4d0ea2
13 changed files with 48 additions and 74 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue