Skip to content

Commit b6bee18

Browse files
committed
ACP2E-4031: [QUANS] Confirm GQL order placement exception handling behaviour reversion
1 parent 11553b6 commit b6bee18

File tree

6 files changed

+15
-10
lines changed

6 files changed

+15
-10
lines changed

app/code/Magento/GraphQl/Helper/Error/AggregateExceptionMessageFormatter.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ public function getFormatted(
5959
}
6060
}
6161

62-
$message = $e->getCode() ? __($e->getMessage()) : $defaultMessage;
63-
return new GraphQlInputException($message, $e, $e->getCode());
62+
$messageText = $e->getCode() ? __($e->getMessage()) : $defaultMessage;
63+
$messageWithPrefix = empty($messagePrefix)
64+
? $messageText
65+
: __("$messagePrefix: %message", ['message' => $messageText]);
66+
return new GraphQlInputException($messageWithPrefix, $e, $e->getCode());
6467
}
6568
}

app/code/Magento/GraphQl/Test/Unit/Helper/Error/AggregateExceptionMessageFormatterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function testGetFormattedExceptionMessage(): void
118118
);
119119
$this->assertInstanceOf(GraphQlInputException::class, $exception);
120120
$this->assertSame($exceptionCode, $exception->getCode());
121-
$this->assertSame($exceptionMessage, $exception->getMessage());
121+
$this->assertSame($messagePrefix . ": " . $exceptionMessage, $exception->getMessage());
122122
}
123123

124124
/**
@@ -127,7 +127,7 @@ public function testGetFormattedExceptionMessage(): void
127127
public function testGetFormattedDefaultMessage(): void
128128
{
129129
$exceptionMessage = 'exception message';
130-
$messagePrefix = 'prefix';
130+
$messagePrefix = '';
131131
$this->formatter->expects($this->once())
132132
->method('getFormatted')
133133
->willReturn(null);

app/code/Magento/QuoteGraphQl/Model/ErrorMapper.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class ErrorMapper
4343
'Please check the billing address information' => self::ERROR_UNABLE_TO_PLACE_ORDER_ID,
4444
'Enter a valid payment method and try again' => self::ERROR_UNABLE_TO_PLACE_ORDER_ID,
4545
'Some of the products are out of stock' => self::ERROR_UNABLE_TO_PLACE_ORDER_ID,
46+
'Unable to place order' => self::ERROR_UNABLE_TO_PLACE_ORDER_ID,
4647
];
4748

4849
/**

app/code/Magento/QuoteGraphQl/Model/OrderErrorProcessor.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,23 @@ public function __construct(
3131
* @param Field $field
3232
* @param $context
3333
* @param ResolveInfo $info
34-
* @return array
3534
* @throws GraphQlAuthorizationException
3635
* @throws QuoteException
3736
*/
3837
public function execute(
3938
LocalizedException $exception,
40-
Field $field, $context,
39+
Field $field,
40+
$context,
4141
ResolveInfo $info
42-
): array {
42+
): void {
4343
if ($exception instanceof AuthorizationException) {
4444
throw new GraphQlAuthorizationException(
4545
__($exception->getMessage())
4646
);
4747
}
4848
$exception = $this->errorMessageFormatter->getFormatted(
4949
$exception,
50-
__('Unable to place order: A server error stopped your order from being placed. ' .
50+
__('A server error stopped your order from being placed. ' .
5151
'Please try to place your order again'),
5252
'Unable to place order',
5353
$field,
@@ -58,6 +58,7 @@ public function execute(
5858
if (!$exceptionCode) {
5959
$exceptionCode = $this->errorMapper->getErrorMessageId($exception->getRawMessage());
6060
}
61+
6162
throw new QuoteException(__($exception->getMessage()), $exception, $exceptionCode);
6263
}
6364
}

dev/tests/integration/testsuite/Magento/PaypalGraphQl/Model/Resolver/Guest/PlaceOrderWithPayflowLinkTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public function testResolveWithPayflowLinkDeclined(): void
248248
$resultCode = Payflowlink::RESPONSE_CODE_DECLINED_BY_FILTER;
249249
$exception = new RuntimeException(__('Declined response message from PayPal gateway')->render());
250250
//Exception message is transformed into more controlled message
251-
$expectedErrorCode = 'UNDEFINED';
251+
$expectedErrorCode = 'UNABLE_TO_PLACE_ORDER';
252252

253253
$this->payflowRequest->method('setData')
254254
->with(

dev/tests/integration/testsuite/Magento/PaypalGraphQl/Model/Resolver/Guest/PlaceOrderWithPaymentsAdvancedTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public function testResolveWithPaymentAdvancedDeclined(): void
208208
$resultCode = Payflowlink::RESPONSE_CODE_DECLINED_BY_FILTER;
209209
$exception = new RuntimeException(__('Declined response message from PayPal gateway')->render());
210210
//Exception message is transformed into more controlled message
211-
$expectedErrorCode = 'UNDEFINED';
211+
$expectedErrorCode = 'UNABLE_TO_PLACE_ORDER';
212212

213213
$this->paymentRequest->method('setData')
214214
->with(

0 commit comments

Comments
 (0)