Enhance gift sending logic: Implement retry mechanism for 'tooOften' error in FalukantService and update error handling in FamilyView to display retry time.
This commit is contained in:
@@ -99,7 +99,16 @@ class FalukantController {
|
||||
return this.service.getGifts(userId);
|
||||
});
|
||||
this.getChildren = this._wrapWithUser((userId) => this.service.getChildren(userId));
|
||||
this.sendGift = this._wrapWithUser((userId, req) => this.service.sendGift(userId, req.body.giftId));
|
||||
this.sendGift = this._wrapWithUser(async (userId, req) => {
|
||||
try {
|
||||
return await this.service.sendGift(userId, req.body.giftId);
|
||||
} catch (e) {
|
||||
if (e && e.name === 'PreconditionError' && e.message === 'tooOften') {
|
||||
throw { status: 412, message: 'tooOften', retryAt: e.meta?.retryAt };
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
this.getTitlesOfNobility = this._wrapWithUser((userId) => this.service.getTitlesOfNobility(userId));
|
||||
this.getHouseTypes = this._wrapWithUser((userId) => this.service.getHouseTypes(userId));
|
||||
|
||||
@@ -2868,7 +2868,10 @@ class FalukantService extends BaseService {
|
||||
limit: 1
|
||||
});
|
||||
if (lastGift && (lastGift.createdAt.getTime() + 3_600_000) > Date.now()) {
|
||||
throw new PreconditionError('tooOften');
|
||||
const retryAt = new Date(lastGift.createdAt.getTime() + 3_600_000);
|
||||
const err = new PreconditionError('tooOften');
|
||||
err.meta = { retryAt: retryAt.toISOString() };
|
||||
throw err;
|
||||
}
|
||||
const gift = await PromotionalGift.findOne({
|
||||
where: { id: giftId },
|
||||
|
||||
Reference in New Issue
Block a user