Forked from tarlepp/gist:d89d32e155cc26a1a9926737af633066
Last active
May 3, 2018 15:34
-
-
Save nicholasruunu/ed2a6acfb64b6fb0741fe08e4bf6b786 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @throws AdressApiDown | |
*/ | |
public function validate($value, Constraint $constraint): void | |
{ | |
try { | |
if ($someService->checkValue($value)) { | |
$this->context | |
->buildViolation($constraint->message) | |
->addViolation(); | |
} | |
} catch (\Exception $exception) { | |
throw new AdressApiDown('...', 0 , $exception); | |
} | |
} | |
// Controller | |
try { | |
$validator->validate($adress); | |
} catch (AdressApiDown $e) { | |
return new JsonResponse(['error' => 'Adress API down, try later.'], 503); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment