protected function convertException(\Exception $exception)
{
if ($this->objectManager->getContext()->isProduction()) {
if ($exception instanceof FlowException) {
$exceptionData['message'] = 'When contacting the maintainer of this application please mention the following reference code:<br /><br />' . $exception->getReferenceCode();
}
} else {
$exceptionData = array('code' => $exception->getCode(), 'message' => $exception->getMessage());
$splitMessagePattern = '/
(?<= # Begin positive lookbehind.
[.!?]\\s # Either an end of sentence punct,
| \\n # or line break
)
(?<! # Begin negative lookbehind.
i\\.E\\.\\s # Skip "i.E."
) # End negative lookbehind.
/ix';
$sentences = preg_split($splitMessagePattern, $exception->getMessage(), 2, PREG_SPLIT_NO_EMPTY);
if (!isset($sentences[1])) {
$exceptionData['message'] = $exception->getMessage();
} else {
$exceptionData['message'] = trim($sentences[0]);
$exceptionData['details'] = trim($sentences[1]);
}
if ($exception instanceof FlowException) {
$exceptionData['referenceCode'] = $exception->getReferenceCode();
}
if ($exception->getPrevious() !== null) {
$exceptionData['previous'] = $this->convertException($exception->getPrevious());
}
}
return $exceptionData;
}