Skip to content

Commit

Permalink
Add edit uri to additional data
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Lehmann committed Mar 9, 2024
1 parent 8d7b7d2 commit 85e1c91
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion Classes/Content/ProductionExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

use Networkteam\SentryClient\Client;
use Networkteam\SentryClient\Service\ConfigurationService;
use Sentry\State\Scope;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\AbstractContentObject;
use function Sentry\withScope;

class ProductionExceptionHandler extends \TYPO3\CMS\Frontend\ContentObject\Exception\ProductionExceptionHandler
{
Expand All @@ -25,12 +28,37 @@ public function handle(
throw $exception;
}

$eventId = GeneralUtility::makeInstance(Client::class)->captureException($exception);
$eventId = '';
withScope(function (Scope $scope) use ($exception, $contentObject, &$eventId): void {
$currentRecord = $contentObject?->getContentObjectRenderer()?->currentRecord;
if (!empty($currentRecord)) {
$scope->setExtra('Edit record', $this->getEditUri($currentRecord));
}
$eventId = Client::captureException($exception);
});

$errorMessage = parent::handle($exception, $contentObject, $contentObjectConfiguration);

if (ConfigurationService::showEventId()) {
return sprintf('%s Event: %s', $errorMessage, $eventId);
}
return $errorMessage;
}

protected function getEditUri(string $currentRecord): ?string
{
[$tableName, $uid] = GeneralUtility::trimExplode(':', $currentRecord);
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
try {
$editUri = (string)$uriBuilder->buildUriFromRoute(
'record_edit',
[
'edit[' . $tableName . '][' . $uid . ']' => 'edit',
],
UriBuilder::SHAREABLE_URL
);
return $editUri;
} catch (\Throwable) {}
return null;
}
}

0 comments on commit 85e1c91

Please sign in to comment.