twenty / packages /twenty-server /src /modules /dashboard /utils /dashboard-graphql-api-exception-handler.util.ts
Jules
Initial clean CRM deployment with prebuilt assets
d9494a5
Raw
History Blame Contribute Delete
864 Bytes
import { assertUnreachable } from 'twenty-shared/utils';
import {
InternalServerError,
NotFoundError,
} from 'src/engine/core-modules/graphql/utils/graphql-errors.util';
import {
DashboardException,
DashboardExceptionCode,
} from 'src/modules/dashboard/exceptions/dashboard.exception';
export const dashboardGraphqlApiExceptionHandler = (error: Error) => {
if (error instanceof DashboardException) {
switch (error.code) {
case DashboardExceptionCode.DASHBOARD_NOT_FOUND:
throw new NotFoundError(error.message);
case DashboardExceptionCode.PAGE_LAYOUT_NOT_FOUND:
throw new NotFoundError(error.message);
case DashboardExceptionCode.DASHBOARD_DUPLICATION_FAILED:
throw new InternalServerError(error.message);
default: {
return assertUnreachable(error.code);
}
}
}
throw error;
};