fix: impact too many records (#3993)

* fix: impact too many records

* fix: change env name

* fix: remove env name from error
This commit is contained in:
Jérémy M
2024-02-16 11:17:37 +01:00
committed by GitHub
parent c2c14d79a9
commit 44ac16c82e
12 changed files with 107 additions and 39 deletions

View File

@ -0,0 +1,34 @@
import {
BadRequestException,
HttpException,
InternalServerErrorException,
} from '@nestjs/common';
interface PgGraphQLErrorMapping {
[key: string]: (command: string, objectName: string) => HttpException;
}
const pgGraphQLErrorMapping: PgGraphQLErrorMapping = {
'delete impacts too many records': (command, objectName) =>
new BadRequestException(
`Cannot ${command} ${objectName} because it impacts too many records.`,
),
};
export const computePgGraphQLError = (
command: string,
objectName: string,
errors: any[],
) => {
const error = errors[0];
const errorMessage = error?.message;
const mappedError = pgGraphQLErrorMapping[errorMessage];
if (mappedError) {
return mappedError(command, objectName);
}
return new InternalServerErrorException(
`GraphQL errors on ${command}${objectName}: ${JSON.stringify(error)}`,
);
};