Skip to content

Commit 6a8ce85

Browse files
committed
ACP2E-4033: Issue mapping translated message to error code when placing order via GraphQL
1 parent e01e04b commit 6a8ce85

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
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,8 +59,11 @@ public function getFormatted(
5959
}
6060
}
6161

62-
$message = $e->getCode() ? __($e->getMessage()) : $defaultMessage;
62+
$messageText = $e->getCode() ? __($e->getMessage()) : $defaultMessage;
63+
$messageWithPrefix = empty($messagePrefix)
64+
? $messageText
65+
: __("$messagePrefix: %message", ['message' => $messageText]);
6366

64-
return new GraphQlInputException(__("$messagePrefix: %message", ['message' => $message]), $e, $e->getCode());
67+
return new GraphQlInputException($messageWithPrefix, $e, $e->getCode());
6568
}
6669
}

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);

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)