diff --git a/src/request-management/request-management.service.ts b/src/request-management/request-management.service.ts index 6a2c4b1..a877168 100644 --- a/src/request-management/request-management.service.ts +++ b/src/request-management/request-management.service.ts @@ -158,6 +158,16 @@ export class RequestManagementService { }; } + /** Keep eligibility rejections distinct from an unavailable CAR_BODY provider. */ + private throwCarBodyInquiryFailure(err: unknown): never { + if (err instanceof ForbiddenException) throw err; + + throw new HttpException( + "Car body inquiry failed", + HttpStatus.BAD_REQUEST, + ); + } + private stepKeyToPartyRole(stepKey: WorkflowStep): PartyRole { if (String(stepKey).startsWith("FIRST_")) return PartyRole.FIRST; if (String(stepKey).startsWith("SECOND_")) return PartyRole.SECOND; @@ -1563,10 +1573,7 @@ export class RequestManagementService { await this.blameRequestDbService.findByIdAndUpdate(req._id, { $set: { inquiries: req.inquiries }, }); - throw new HttpException( - "Car body inquiry failed", - HttpStatus.BAD_REQUEST, - ); + this.throwCarBodyInquiryFailure(err); } // Raw + mapped stored under vehicle @@ -2041,10 +2048,7 @@ export class RequestManagementService { await this.blameRequestDbService.findByIdAndUpdate(req._id, { $set: { inquiries: req.inquiries }, }); - throw new HttpException( - "Car body inquiry failed", - HttpStatus.BAD_REQUEST, - ); + this.throwCarBodyInquiryFailure(err); } } @@ -3174,6 +3178,7 @@ export class RequestManagementService { ); } catch (er) { this.logger.error(er); + if (er instanceof HttpException) throw er; throw new InternalServerErrorException( "Failed to update request with plate details.", ); @@ -7369,6 +7374,7 @@ export class RequestManagementService { stepsToAdd.push(StepsEnum.F_addPlate); } catch (plateError) { this.logger.error("Error processing first party plate:", plateError); + if (plateError instanceof HttpException) throw plateError; throw new InternalServerErrorException( "Failed to process first party plate information", ); @@ -9009,9 +9015,7 @@ export class RequestManagementService { {}, err, ); - throw new BadRequestException( - `CAR_BODY inquiry failed: ${err?.message || "استعلام در دسترس نیست"}`, - ); + this.throwCarBodyInquiryFailure(err); } } @@ -9861,9 +9865,7 @@ export class RequestManagementService { {}, err, ); - throw new BadRequestException( - `CAR_BODY VIN inquiry failed: ${err?.message || "استعلام در دسترس نیست"}`, - ); + this.throwCarBodyInquiryFailure(err); } }