From 9eceb51d78509ba5c88c4daed753d5a70ec57c22 Mon Sep 17 00:00:00 2001 From: vol4onok Date: Tue, 3 Sep 2024 12:28:08 +0300 Subject: [PATCH] ACP-3792: Send Code with error message --- .../Glue/AppKernel/Mapper/GlueRequestMapper.php | 4 +++- .../_support/Helper/AppKernelAssertionHelper.php | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Spryker/Glue/AppKernel/Mapper/GlueRequestMapper.php b/src/Spryker/Glue/AppKernel/Mapper/GlueRequestMapper.php index 4c8ea5a..482ac8a 100644 --- a/src/Spryker/Glue/AppKernel/Mapper/GlueRequestMapper.php +++ b/src/Spryker/Glue/AppKernel/Mapper/GlueRequestMapper.php @@ -59,11 +59,13 @@ public function mapConfigurationValidationResponseTransferToGlueRequestValidatio ->setStatus($configurationValidationResponseTransfer->getIsSuccessful() === false ? Response::HTTP_UNPROCESSABLE_ENTITY : null); if ($configurationValidationResponseTransfer->getIsSuccessful() === false) { + $status = $configurationValidationResponseTransfer->getExceptionMessage() !== null && $configurationValidationResponseTransfer->getExceptionMessage() !== '' && $configurationValidationResponseTransfer->getExceptionMessage() !== '0' ? Response::HTTP_INTERNAL_SERVER_ERROR : Response::HTTP_UNPROCESSABLE_ENTITY; $glueErrorTransfer = new GlueErrorTransfer(); $glueErrorTransfer->setMessage($configurationValidationResponseTransfer->getMessage() ?? $configurationValidationResponseTransfer->getExceptionMessage()); + $glueErrorTransfer->setCode((string)$status); $glueRequestValidationTransfer->addError($glueErrorTransfer); - $glueRequestValidationTransfer->setStatus($configurationValidationResponseTransfer->getExceptionMessage() !== null && $configurationValidationResponseTransfer->getExceptionMessage() !== '' && $configurationValidationResponseTransfer->getExceptionMessage() !== '0' ? Response::HTTP_INTERNAL_SERVER_ERROR : Response::HTTP_UNPROCESSABLE_ENTITY); + $glueRequestValidationTransfer->setStatus($status); } return $glueRequestValidationTransfer; diff --git a/tests/SprykerTest/Glue/AppKernel/_support/Helper/AppKernelAssertionHelper.php b/tests/SprykerTest/Glue/AppKernel/_support/Helper/AppKernelAssertionHelper.php index 60fd609..e3e331e 100644 --- a/tests/SprykerTest/Glue/AppKernel/_support/Helper/AppKernelAssertionHelper.php +++ b/tests/SprykerTest/Glue/AppKernel/_support/Helper/AppKernelAssertionHelper.php @@ -53,6 +53,10 @@ public function assertGlueResponseContainsErrorMessageWhenXTenantIdentifierIsMis 'X-Tenant-Identifier in header is required.', $contentData['errors'][0]['message'], ); + $this->assertEquals( + Response::HTTP_UNPROCESSABLE_ENTITY, + $contentData['errors'][0]['code'], + ); } /** @@ -71,6 +75,10 @@ public function assertGlueResponseContainsErrorMessageWhenRequestBodyHasInvalidS 'Wrong request format.', $contentData['errors'][0]['message'], ); + $this->assertEquals( + Response::HTTP_UNPROCESSABLE_ENTITY, + $contentData['errors'][0]['code'], + ); } /** @@ -88,6 +96,10 @@ public function assertGlueResponseContainsErrorMessageWhenExceptionWasThrown(Glu 'Tenant action failed: Something went wrong', $contentData['errors'][0]['message'], ); + $this->assertEquals( + Response::HTTP_UNPROCESSABLE_ENTITY, + $contentData['errors'][0]['code'], + ); } /**