Skip to content

Commit 4eedd8e

Browse files
committed
AC-746: Malformed request body or parameters cause "Internal Server Error"
Re-throw other exceptions as WebapiException with 400 status code
1 parent 536edc2 commit 4eedd8e

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

app/code/Magento/Webapi/Controller/Rest/SynchronousRequestProcessor.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
use Magento\Framework\App\DeploymentConfig;
1414
use Magento\Framework\ObjectManagerInterface;
1515
use Magento\Framework\Config\ConfigOptionsListConstants;
16+
use Magento\Framework\Phrase;
17+
use Magento\Framework\Webapi\Exception as WebapiException;
1618

1719
/**
1820
* REST request processor for synchronous requests
@@ -92,7 +94,17 @@ public function process(\Magento\Framework\Webapi\Rest\Request $request)
9294
/**
9395
* @var \Magento\Framework\Api\AbstractExtensibleObject $outputData
9496
*/
95-
$outputData = call_user_func_array([$service, $serviceMethodName], $inputParams);
97+
try {
98+
$outputData = call_user_func_array([$service, $serviceMethodName], $inputParams);
99+
} catch (\Exception $e) {
100+
// Re-throw other exceptions as WebapiException with 400 status code
101+
throw new WebapiException(
102+
new Phrase($e->getMessage()),
103+
0,
104+
WebapiException::HTTP_BAD_REQUEST
105+
);
106+
}
107+
96108
$outputData = $this->serviceOutputProcessor->process(
97109
$outputData,
98110
$serviceClassName,

0 commit comments

Comments
 (0)