Migrate to a monorepo structure (#2909)
This commit is contained in:
27
packages/twenty-server/src/utils/assert.ts
Normal file
27
packages/twenty-server/src/utils/assert.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { HttpException } from '@nestjs/common';
|
||||
|
||||
type Assert = (
|
||||
condition: unknown,
|
||||
message?: string,
|
||||
ErrorType?: new (message?: string) => HttpException,
|
||||
) => asserts condition;
|
||||
|
||||
/**
|
||||
* assert condition and throws a HttpException
|
||||
*/
|
||||
export const assert: Assert = (condition, message, ErrorType) => {
|
||||
if (!condition) {
|
||||
if (ErrorType) {
|
||||
if (message) {
|
||||
throw new ErrorType(message);
|
||||
}
|
||||
|
||||
throw new ErrorType();
|
||||
}
|
||||
|
||||
throw new Error(message);
|
||||
}
|
||||
};
|
||||
|
||||
export const assertNotNull = <T>(item: T): item is NonNullable<T> =>
|
||||
item !== null && item !== undefined;
|
||||
Reference in New Issue
Block a user