056e3a4cd8
- update ci-breaking-changes.yaml so it check for api contrat breaks - check fails properly when removing fix https://github.com/twentyhq/twenty/pull/20825 - check it turns green again when adding fix back
29 lines
633 B
TypeScript
29 lines
633 B
TypeScript
import { type 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 assertNever = (_value: never, message?: string): never => {
|
|
throw new Error(message ?? "Didn't expect to get here.");
|
|
};
|