Answer the question
In order to leave comments, you need to log in
Proper exception handling from external symfony api?
Hello. There is a certain api that I work with through guzzle. API processing is divided into 3 levels. Controller, manager, api service.
I would like to notify about an error in the controller, what specifically happened wrong in the api. Should I wrap the manager call block that calls the api directly in the controller, or process it differently, through some models. For example, the api service would return the result valid or not, and process it already in the manager?
Answer the question
In order to leave comments, you need to log in
you can create error classes. And throw exceptions in certain cases, dividing them into categories of "happened", and in the controller you can hang handlers on one or another type of exception.
Here is an example from my code:
try {
$results = $core->execute($coreConfig);
}
catch (BreakpointException $e) {
throw $e;
}
catch (StrategiesException $e) {
$this->mark("Expected error:".$e->getMessage());
return $this->formattingResult(ProcessRecord::STATUS_ERROR,$e->getMessage());
}
catch (\Exception $e) {
$this->mark("Unexpected error:".$e->getMessage()."[".$e->getFile()."] : ".$e->getLine());
return $this->formattingResult(ProcessRecord::STATUS_UNEXPECTED_ERROR,$e->getMessage());
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question