Skip to content

Commit

Permalink
ACP-3792: Send Code with error message
Browse files Browse the repository at this point in the history
  • Loading branch information
vol4onok committed Sep 3, 2024
1 parent 691c91b commit 9eceb51
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Spryker/Glue/AppKernel/Mapper/GlueRequestMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
);
}

/**
Expand All @@ -71,6 +75,10 @@ public function assertGlueResponseContainsErrorMessageWhenRequestBodyHasInvalidS
'Wrong request format.',
$contentData['errors'][0]['message'],
);
$this->assertEquals(
Response::HTTP_UNPROCESSABLE_ENTITY,
$contentData['errors'][0]['code'],
);
}

/**
Expand All @@ -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'],
);
}

/**
Expand Down

0 comments on commit 9eceb51

Please sign in to comment.