From f75bf9940d8e8e66f499bccd7c0ab7a0b0fe6d0d Mon Sep 17 00:00:00 2001 From: Roger Date: Wed, 13 Dec 2023 17:19:16 +0000 Subject: [PATCH 1/6] Internal Server Error in /V1/order/{orderId}/ship API Endpoint --- .../Magento/Framework/Webapi/ServiceInputProcessor.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/internal/Magento/Framework/Webapi/ServiceInputProcessor.php b/lib/internal/Magento/Framework/Webapi/ServiceInputProcessor.php index cd7960409e164..b857b68421997 100644 --- a/lib/internal/Magento/Framework/Webapi/ServiceInputProcessor.php +++ b/lib/internal/Magento/Framework/Webapi/ServiceInputProcessor.php @@ -7,6 +7,7 @@ namespace Magento\Framework\Webapi; +use Laminas\Code\Reflection\ClassReflection; use Magento\Framework\Api\AttributeValue; use Magento\Framework\Api\AttributeValueFactory; use Magento\Framework\Api\SearchCriteriaInterface; @@ -22,9 +23,8 @@ use Magento\Framework\Phrase; use Magento\Framework\Reflection\MethodsMap; use Magento\Framework\Reflection\TypeProcessor; -use Magento\Framework\Webapi\Exception as WebapiException; use Magento\Framework\Webapi\CustomAttribute\PreprocessorInterface; -use Laminas\Code\Reflection\ClassReflection; +use Magento\Framework\Webapi\Exception as WebapiException; use Magento\Framework\Webapi\Validator\IOLimit\DefaultPageSizeSetter; use Magento\Framework\Webapi\Validator\ServiceInputValidatorInterface; @@ -539,6 +539,8 @@ private function processComplexTypes($data, $type) if (!$isArrayType) { return $this->_createFromArray($type, $data); + } elseif (!is_array($data)) { + throw new InvalidArgumentException(__('Not all parameters valid.')); } $result = is_array($data) ? [] : null; From c96bcda7f731cb208fd4b9699784c9024628ef7d Mon Sep 17 00:00:00 2001 From: rogerdz Date: Tue, 10 Jun 2025 09:19:27 +0000 Subject: [PATCH 2/6] update code --- .../Webapi/Controller/Rest/SynchronousRequestProcessor.php | 7 ++++++- .../Magento/Framework/Webapi/ServiceInputProcessor.php | 6 ++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Webapi/Controller/Rest/SynchronousRequestProcessor.php b/app/code/Magento/Webapi/Controller/Rest/SynchronousRequestProcessor.php index f5aa6bd88c399..7adadde5dbc88 100644 --- a/app/code/Magento/Webapi/Controller/Rest/SynchronousRequestProcessor.php +++ b/app/code/Magento/Webapi/Controller/Rest/SynchronousRequestProcessor.php @@ -7,6 +7,7 @@ namespace Magento\Webapi\Controller\Rest; +use Magento\Framework\Webapi\Exception as WebapiException; use Magento\Framework\Webapi\Rest\Response as RestResponse; use Magento\Framework\Webapi\ServiceOutputProcessor; use Magento\Framework\Webapi\Rest\Response\FieldsFilter; @@ -92,7 +93,11 @@ public function process(\Magento\Framework\Webapi\Rest\Request $request) /** * @var \Magento\Framework\Api\AbstractExtensibleObject $outputData */ - $outputData = call_user_func_array([$service, $serviceMethodName], $inputParams); + try { + $outputData = call_user_func_array([$service, $serviceMethodName], $inputParams); + } catch (\Throwable $e) { + throw new WebapiException(__($e->getMessage())); + } $outputData = $this->serviceOutputProcessor->process( $outputData, $serviceClassName, diff --git a/lib/internal/Magento/Framework/Webapi/ServiceInputProcessor.php b/lib/internal/Magento/Framework/Webapi/ServiceInputProcessor.php index 8d68a2284ab95..ba58dc2bc7acf 100644 --- a/lib/internal/Magento/Framework/Webapi/ServiceInputProcessor.php +++ b/lib/internal/Magento/Framework/Webapi/ServiceInputProcessor.php @@ -7,7 +7,6 @@ namespace Magento\Framework\Webapi; -use Laminas\Code\Reflection\ClassReflection; use Magento\Framework\Api\AttributeValue; use Magento\Framework\Api\AttributeValueFactory; use Magento\Framework\Api\SearchCriteriaInterface; @@ -23,8 +22,9 @@ use Magento\Framework\Phrase; use Magento\Framework\Reflection\MethodsMap; use Magento\Framework\Reflection\TypeProcessor; -use Magento\Framework\Webapi\CustomAttribute\PreprocessorInterface; use Magento\Framework\Webapi\Exception as WebapiException; +use Magento\Framework\Webapi\CustomAttribute\PreprocessorInterface; +use Laminas\Code\Reflection\ClassReflection; use Magento\Framework\Webapi\Validator\IOLimit\DefaultPageSizeSetter; use Magento\Framework\Webapi\Validator\ServiceInputValidatorInterface; @@ -564,8 +564,6 @@ private function processComplexTypes($data, $type) if (!$isArrayType) { return $this->_createFromArray($type, $data); - } elseif (!is_array($data)) { - throw new InvalidArgumentException(__('Not all parameters valid.')); } $result = is_array($data) ? [] : null; From 0e40e85fc607d7f402a72067dab2fda177b9afb6 Mon Sep 17 00:00:00 2001 From: rogerdz Date: Tue, 10 Jun 2025 09:24:55 +0000 Subject: [PATCH 3/6] update code --- .../Controller/Rest/SynchronousRequestProcessor.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Webapi/Controller/Rest/SynchronousRequestProcessor.php b/app/code/Magento/Webapi/Controller/Rest/SynchronousRequestProcessor.php index 7adadde5dbc88..e43d178d58b68 100644 --- a/app/code/Magento/Webapi/Controller/Rest/SynchronousRequestProcessor.php +++ b/app/code/Magento/Webapi/Controller/Rest/SynchronousRequestProcessor.php @@ -1,7 +1,7 @@ getMessage())); } @@ -114,7 +116,7 @@ public function process(\Magento\Framework\Webapi\Rest\Request $request) } /** - * {@inheritdoc} + * @inheritdoc */ public function canProcess(\Magento\Framework\Webapi\Rest\Request $request) { From b0c88f6f83d6f488e4b00fb58f9e98d3c594b82a Mon Sep 17 00:00:00 2001 From: rogerdz Date: Tue, 10 Jun 2025 16:18:08 +0000 Subject: [PATCH 4/6] add test --- .../Rest/SynchronousRequestProcessor.php | 2 +- .../Magento/Sales/Service/V1/ShipOrderTest.php | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Webapi/Controller/Rest/SynchronousRequestProcessor.php b/app/code/Magento/Webapi/Controller/Rest/SynchronousRequestProcessor.php index e43d178d58b68..7e141a1c56aa9 100644 --- a/app/code/Magento/Webapi/Controller/Rest/SynchronousRequestProcessor.php +++ b/app/code/Magento/Webapi/Controller/Rest/SynchronousRequestProcessor.php @@ -97,7 +97,7 @@ public function process(\Magento\Framework\Webapi\Rest\Request $request) // phpcs:disable Magento2.Functions.DiscouragedFunction $outputData = call_user_func_array([$service, $serviceMethodName], $inputParams); // phpcs:enable Magento2.Functions.DiscouragedFunction - } catch (\Throwable $e) { + } catch (\TypeError $e) { throw new WebapiException(__($e->getMessage())); } $outputData = $this->serviceOutputProcessor->process( diff --git a/dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/ShipOrderTest.php b/dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/ShipOrderTest.php index 41b03933f40a2..aa4dc90d55a93 100644 --- a/dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/ShipOrderTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/ShipOrderTest.php @@ -181,6 +181,23 @@ public function testShipOrder() ); } + /** + * @magentoApiDataFixture Magento/Sales/_files/order_new.php + */ + public function testShipOrderWithTypeError() + { + /** @var Order $existingOrder */ + $existingOrder = $this->getOrder('100000001'); + + $requestData = [ + 'orderId' => $existingOrder->getId(), + 'items' => "[]", + ]; + + $this->expectExceptionCode(400); + $this->_webApiCall($this->getServiceInfo($existingOrder), $requestData); + } + /** * Tests that not providing a tracking number produces the correct error. See MAGETWO-95429 * @codingStandardsIgnoreStart From 80896cef9831d90ac4641f4101e6dcb062de9c69 Mon Sep 17 00:00:00 2001 From: rogerdz Date: Tue, 10 Jun 2025 16:19:57 +0000 Subject: [PATCH 5/6] update code --- .../testsuite/Magento/Sales/Service/V1/ShipOrderTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/ShipOrderTest.php b/dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/ShipOrderTest.php index aa4dc90d55a93..66197a72a0487 100644 --- a/dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/ShipOrderTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/ShipOrderTest.php @@ -1,7 +1,7 @@ Date: Wed, 11 Jun 2025 03:53:48 +0000 Subject: [PATCH 6/6] update code --- .../testsuite/Magento/Sales/Service/V1/ShipOrderTest.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/ShipOrderTest.php b/dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/ShipOrderTest.php index 66197a72a0487..3a2ccf053b4d0 100644 --- a/dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/ShipOrderTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/ShipOrderTest.php @@ -194,8 +194,11 @@ public function testShipOrderWithTypeError() 'items' => "[]", ]; - $this->expectExceptionCode(400); - $this->_webApiCall($this->getServiceInfo($existingOrder), $requestData); + try { + $this->_webApiCall($this->getServiceInfo($existingOrder), $requestData); + $this->fail('Expected exception was not raised'); + } catch (\Exception $exception) { + } } /**