We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I work on NestJs and build a FilterException to handle Mikroorm Error separate.
// postgresException.filter.ts import { DriverException } from "@mikro-orm/core"; @Catch(DriverException) export class PostgresExceptionFilter implements ExceptionFilter { constructor(private readonly httpAdapterHost?: HttpAdapterHost) {} catch(exception: DriverException, host: ArgumentsHost): void { const { httpAdapter } = this.httpAdapterHost; const ctx = host.switchToHttp(); const dataResponse: IErrorResponseData = { status: false, errorCode: HttpStatus.INTERNAL_SERVER_ERROR, message: exception["detail"] || exception.message, metaData: { dbCode: exception.code } }; (process.env.NODE_ENV == "development" || process.env.NODE_ENV == "local") && console.log("LOG_POSTGRES_EXCEPTION", exception); httpAdapter.reply(ctx.getResponse(), dataResponse, HttpStatus.INTERNAL_SERVER_ERROR); } }
It works on almost cases. When I upsert, it not raise DriverError, just Error:
await this.em.upsertMany(Enroll, enrollmentUpserts, { onConflictFields: ["user", "course"], onConflictAction: "ignore" }); error: insert into "course"."enroll" ("course_id", "register_at", "user_id") values (32, '2023-11-05T18:16:27.381Z', 1), (32, '2023-11-05T18:16:27.381Z', 2), (32, '2023-11-05T18:16:27.381Z', 4), (32, '2023-11-05T18:16:27.381Z', 5), (32, '2023-11-05T18:16:27.381Z', 1001) on conflict ("user_id", "course_id") do nothing returning "register_at", "expired_at" - insert or update on table "enroll" violates foreign key constraint "enroll_user_id_foreign" It would be ForeignKeyConstraintViolationException: insert into "course"."enroll" ("course_id", "register_at", "user_id") values (32, '2023-11-05T18:16:27.381Z', 1), (32, '2023-11-05T18:16:27.381Z', 2), (32, '2023-11-05T18:16:27.381Z', 4), (32, '2023-11-05T18:16:27.381Z', 5), (32, '2023-11-05T18:16:27.381Z', 1001) on conflict ("user_id", "course_id") do nothing returning "register_at", "expired_at" - insert or update on table "enroll" violates foreign key constraint "enroll_user_id_foreign"
The text was updated successfully, but these errors were encountered:
615f223
fix(core): return DriverException from em.upsertMany()
DriverException
em.upsertMany()
1ebfbdd
Closes #4897
No branches or pull requests
I work on NestJs and build a FilterException to handle Mikroorm Error separate.
It works on almost cases. When I upsert, it not raise DriverError, just Error:
The text was updated successfully, but these errors were encountered: