Skip to content

Instantly share code, notes, and snippets.

@LarsNieuwenhuizen
Last active June 14, 2016 06:42
Show Gist options
  • Save LarsNieuwenhuizen/52df38fb4fc745b039cf2b1b27ef52f7 to your computer and use it in GitHub Desktop.
Save LarsNieuwenhuizen/52df38fb4fc745b039cf2b1b27ef52f7 to your computer and use it in GitHub Desktop.
Flow/Neos Custom ThrowingHandler with bugsnag reporting
TYPO3:
TypoScript:
rendering:
exceptionHandler: 'Vendor\PackageKey\Error\ExceptionHandlers\ThrowingHandler'
Vendor:
PackageKey:
errors:
bugSnag:
apiKey: 'YourApiKeyHere'
<?php
namespace Vendor\PackageKey\Error\ExceptionHandlers;
use Vendor\PackageKey\Service\ProfileService;
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Utility\Environment;
use TYPO3\TYPO3CR\Domain\Model\NodeInterface;
class ThrowingHandler extends \TYPO3\TypoScript\Core\ExceptionHandlers\ThrowingHandler
{
/**
* @Flow\Inject(setting="errors.bugSnag.apiKey", package="Vendor.PackageKey")
* @var string
*/
protected $bugSnagApiKey;
/**
* @Flow\Inject
* @var Environment
*/
protected $environment;
/**
* @Flow\Inject
* @var ProfileService
*/
protected $profileService;
/**
* @param array $typoScriptPath
* @param \Exception $exception
* @return string|void
* @throws \Exception
*/
public function handleRenderingException($typoScriptPath, \Exception $exception)
{
/** @var \Bugsnag_Client $bugSnag -- Sets the error reporting to bugsnag */
$bugSnag = new \Bugsnag_Client($this->getBugSnagApiKey());
set_error_handler(array($bugSnag, 'errorHandler'));
set_exception_handler(array($bugSnag, 'exceptionHandler'));
$bugSnag->setReleaseStage('production');
if ($this->environment->getContext()->isDevelopment()) {
$bugSnag->setReleaseStage('development');
}
$profile = $this->profileService->getCurrentPartyProfile();
if ($profile instanceof NodeInterface) {
$bugSnag->setUser([
'id' => $profile->getIdentifier(),
'user' => $profile->getProperties()
]);
}
$bugSnag->notifyException($exception);
// Default handling
parent::handleRenderingException($typoScriptPath, $exception);
}
/**
* Returns the BugSnagApiKey
*
* @return string
*/
public function getBugSnagApiKey()
{
return $this->bugSnagApiKey;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment