Skip to content

Commit

Permalink
EBOX-1696-Do-not-use-schema-validate-on-production-just-for-developme…
Browse files Browse the repository at this point in the history
…nt (#147)

Co-authored-by: Martin Beranek <[email protected]>
  • Loading branch information
Martin-Beranek and Martin Beranek authored May 13, 2024
1 parent 5347a71 commit 7d99bb7
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions src/Presenters/ApiPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,30 +91,29 @@ public function run(Request $request): IResponse
return $response;
}
$params = $paramsProcessor->getValues();

try {
$response = $handler->handle($params);
$outputValid = count($handler->outputs()) === 0; // back compatibility for handlers with no outputs defined
$outputValidatorErrors = [];
foreach ($handler->outputs() as $output) {
if (!$output instanceof OutputInterface) {
$outputValidatorErrors[] = ["Output does not implement OutputInterface"];
continue;
}
$validationResult = $output->validate($response);
if ($validationResult->isOk()) {
$outputValid = true;
break;
$code = $response->getCode();
if (!Debugger::$productionMode) { /// If not production mode, validate output
$outputValid = count($handler->outputs()) === 0; // back compatibility for handlers with no outputs defined
$outputValidatorErrors = [];
foreach ($handler->outputs() as $output) {
if (!$output instanceof OutputInterface) {
$outputValidatorErrors[] = ["Output does not implement OutputInterface"];
continue;
}
$validationResult = $output->validate($response);
if ($validationResult->isOk()) {
$outputValid = true;
break;
}
$outputValidatorErrors[] = $validationResult->getErrors();
}
$outputValidatorErrors[] = $validationResult->getErrors();
}
if (!$outputValid) {
Debugger::log($outputValidatorErrors, Debugger::ERROR);
if (!Debugger::$productionMode) {
if (!$outputValid) {
Debugger::log($outputValidatorErrors, Debugger::ERROR);
$response = new JsonApiResponse(Response::S500_INTERNAL_SERVER_ERROR, ['status' => 'error', 'message' => 'Internal server error', 'details' => $outputValidatorErrors]);
}
}
$code = $response->getCode();
} catch (Throwable $exception) {
if (!Debugger::$productionMode) {
$response = new JsonApiResponse(Response::S500_INTERNAL_SERVER_ERROR, ['status' => 'error', 'message' => 'Internal server error', 'detail' => $exception->getMessage()]);
Expand Down

0 comments on commit 7d99bb7

Please sign in to comment.