fixed Promise.all Without Error Handling
This commit is contained in:
parent
9a5184bb55
commit
bca04f2881
1 changed files with 23 additions and 5 deletions
|
|
@ -267,11 +267,29 @@ export class AuthRoleController extends Controller {
|
||||||
return newAttr;
|
return newAttr;
|
||||||
});
|
});
|
||||||
const before = structuredClone(record);
|
const before = structuredClone(record);
|
||||||
await Promise.all([
|
|
||||||
this.authRoleRepo.save(record, { data: req }),
|
const queryRunner = AppDataSource.createQueryRunner();
|
||||||
setLogDataDiff(req, { before, after: record }),
|
await queryRunner.connect();
|
||||||
...newAttrs.map((attr) => this.authRoleAttrRepo.save(attr)),
|
await queryRunner.startTransaction();
|
||||||
]);
|
|
||||||
|
try {
|
||||||
|
await queryRunner.manager.save(AuthRole, record);
|
||||||
|
await Promise.all(
|
||||||
|
newAttrs.map((attr) => queryRunner.manager.save(AuthRoleAttr, attr))
|
||||||
|
);
|
||||||
|
await queryRunner.commitTransaction();
|
||||||
|
|
||||||
|
setLogDataDiff(req, { before, after: record });
|
||||||
|
} catch (error) {
|
||||||
|
await queryRunner.rollbackTransaction();
|
||||||
|
console.error("Error saving auth role:", error);
|
||||||
|
throw new HttpError(
|
||||||
|
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||||
|
"เกิดข้อผิดพลาดในการบันทึกข้อมูลบทบาท กรุณาลองใหม่ในภายหลัง"
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
await queryRunner.release();
|
||||||
|
}
|
||||||
|
|
||||||
let redisClient;
|
let redisClient;
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue