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:
@ -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)}`,
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user