Skip to content

Instantly share code, notes, and snippets.

@marcusirgens
Last active March 25, 2019 17:36
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 marcusirgens/16bb28b153fc802db6e64e0b03bcfbea to your computer and use it in GitHub Desktop.
Save marcusirgens/16bb28b153fc802db6e64e0b03bcfbea to your computer and use it in GitHub Desktop.
<?php
/**
* Catch any exceptions, log them and rethrow the exception
*
* @see \Vendor\Library\Class::sendRequest()
* @param $subject
* @param callable $next
* @param mixed ...$args
* @return mixed
* @throws \Throwable
*/
public function aroundSendRequest(
\Vendor\Library\Class $subject,
callable $next,
...$args
) {
try {
return $next(...$args);
} catch (\Throwable $throwable) {
$this->logger->error(
"Error while making request to Vendor: {message}",
[
"message" => $throwable->getMessage(),
"exception" => $throwable,
"request_data" => $args
]
);
throw $throwable;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment