Fixing isssues usins AI

This commit is contained in:
Muluhabt
2026-07-22 17:29:40 +03:00
parent 9782dd0fe3
commit e31a2d64e5
2 changed files with 20 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
import { import {
BadGatewayException, BadGatewayException,
BadRequestException, BadRequestException,
ConflictException,
Injectable, Injectable,
Logger, Logger,
} from "@nestjs/common"; } from "@nestjs/common";
@@ -154,11 +155,16 @@ export class PaymentClientService {
} catch (err) { } catch (err) {
if (err instanceof AxiosError && err.response) { if (err instanceof AxiosError && err.response) {
// 4xx/5xx from the payment service: propagate 404 to callers that handle it; // 4xx/5xx from the payment service: propagate 404 to callers that handle it;
// everything else is a gateway-level failure from the client's perspective. // 409 = a legitimate conflict (e.g. another provider's payment is already in
// flight for this booking) — surface its message as-is rather than masking it as
// a gateway failure; everything else is a genuine gateway-level failure.
if (err.response.status === 404) throw err; if (err.response.status === 404) throw err;
const detail = const detail =
(err.response.data as { message?: string | string[] })?.message ?? (err.response.data as { message?: string | string[] })?.message ??
err.message; err.message;
if (err.response.status === 409) {
throw new ConflictException(detail);
}
this.logger.error( this.logger.error(
`payment service ${method} ${path}${err.response.status}: ${detail}`, `payment service ${method} ${path}${err.response.status}: ${detail}`,
); );

View File

@@ -1,5 +1,6 @@
import { import {
BadRequestException, BadRequestException,
ConflictException,
Inject, Inject,
Injectable, Injectable,
Logger, Logger,
@@ -106,9 +107,19 @@ export class IntentsService {
// so a fresh session opens below. // so a fresh session opens below.
const settled = await this.verifyThenSupersede(existing); const settled = await this.verifyThenSupersede(existing);
if (settled) return this.toSnapshot(settled); if (settled) return this.toSnapshot(settled);
} else if (existing.provider !== request.provider) {
// PROCESSING/SUCCEEDED on a DIFFERENT provider than requested: money may already be
// in flight there. Must not silently hand back that other provider's clientAction
// (e.g. its redirect URL) as if it belonged to the newly requested provider — the
// caller has no way to tell the two apart (see InitiateResponseDto), so it would
// blindly redirect the payer to the wrong gateway's checkout page.
throw new ConflictException(
`A ${existing.provider} payment is already ${existing.status.toLowerCase()} for this ` +
`booking. Complete or wait for it to resolve before switching payment methods.`,
);
} else { } else {
// PROCESSING (money in flight) or SUCCEEDED (already paid): never reopen — // Same provider, already PROCESSING/SUCCEEDED: never reopen — return the existing
// return the existing intent so the caller adopts its outcome. // intent so the caller adopts its outcome.
return this.toSnapshot(existing); return this.toSnapshot(existing);
} }
} }