Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicholasruunu/ed2a6acfb64b6fb0741fe08e4bf6b786 to your computer and use it in GitHub Desktop.
Save nicholasruunu/ed2a6acfb64b6fb0741fe08e4bf6b786 to your computer and use it in GitHub Desktop.
/**
* @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