Fix Inco reader mail handler
This commit is contained in:
parent
b63e7d2ead
commit
2a18baee7e
1 changed files with 80 additions and 3 deletions
|
|
@ -316,14 +316,91 @@ abstract class XmlJobs extends XArcadiaFlux
|
|||
|
||||
protected function sendErrorParseEmailToServiceWeb(Throwable $e)
|
||||
{
|
||||
Mail::send('emails.exception', ['exception' => $e], function ($m) {
|
||||
Mail::send([
|
||||
'html' => 'exception-handler::emails.exception',
|
||||
'text' => 'exception-handler::emails.exception-plain'
|
||||
], [
|
||||
'appName' => config('app.name'),
|
||||
'code' => $e->getCode(),
|
||||
'line' => $e->getLine(),
|
||||
'emessage' => $this->getAnonymizedMessage($e->getMessage()),
|
||||
'file' => str_replace(\realpath(\sprintf('%s/../', \app_path())), '', $e->getFile()),
|
||||
'stackTrace' => $this->getAnonymizedStackTrace($e),
|
||||
'uri' => app()->runningInConsole() ?
|
||||
'CONSOLE' : (
|
||||
(request() and request()->fullUrl()) ?
|
||||
request()->fullUrl() : 'none')
|
||||
], function ($m) {
|
||||
/** @var \Illuminate\Mail\Message $m */
|
||||
$m->to(
|
||||
config('mail.contactsList.serviceweb'),
|
||||
'Le Gaulois Exception Handler'
|
||||
)->subject('Could not eat INCO, because of its toxicity !');
|
||||
sprintf('%s Exception Handler', config('app.name'))
|
||||
)->subject('Need help !, an error occured in your application, please check Logs ASAP');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Anonymize at least Sql queries
|
||||
*
|
||||
* @param string $message
|
||||
* @return string
|
||||
*/
|
||||
private function getAnonymizedMessage(string $message): string
|
||||
{
|
||||
$message = \preg_replace('/^(.*)( \(SQL:.*\))$/', '$1', $message) ?? $message;
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Anonymize stack trace
|
||||
*
|
||||
* @param \Exception $e
|
||||
* @return string
|
||||
*/
|
||||
private function getAnonymizedStackTrace(Throwable $e): string
|
||||
{
|
||||
$projectPath = \realpath(\sprintf('%s/../', \app_path()));
|
||||
$traceStack = $e->getTrace();
|
||||
$traceStr = '';
|
||||
$maxStackStage = 0;
|
||||
foreach ($traceStack as $stackStage => $stack) {
|
||||
$maxStackStage = $stackStage;
|
||||
$traceStr .= \sprintf(
|
||||
'#%s %s(%d): ',
|
||||
$stackStage,
|
||||
str_replace($projectPath, '', $stack['file']),
|
||||
$stack['line']
|
||||
);
|
||||
$traceStr .= "{$stack['class']}->{$stack['function']}(";
|
||||
$traceArgs = '';
|
||||
if (isset($stack['args'])) {
|
||||
$argsCount = count($stack['args']);
|
||||
for ($i = 0; $i < $argsCount; $i++) {
|
||||
$type = \gettype($stack['args'][$i]);
|
||||
switch ($type) {
|
||||
case 'object':
|
||||
$traceArgs .= sprintf('Object(%s)', \get_class($stack['args'][$i]));
|
||||
break;
|
||||
case 'array':
|
||||
$traceArgs .= sprintf('Array(%d)', \count($stack['args'][$i]));
|
||||
break;
|
||||
case 'string':
|
||||
$traceArgs .= sprintf('String(%d)', \strlen($stack['args'][$i]));
|
||||
break;
|
||||
default:
|
||||
$traceArgs .= \gettype($stack['args'][$i]);
|
||||
}
|
||||
$traceArgs .= ($i !== ($argsCount - 1) ? ',' : '');
|
||||
}
|
||||
$traceStr .= $traceArgs;
|
||||
}
|
||||
$traceStr .= ")\n";
|
||||
}
|
||||
$maxStackStage++;
|
||||
$traceStr .= "#$maxStackStage {main}";
|
||||
return $traceStr;
|
||||
}
|
||||
|
||||
protected function sendInvalidXmlEmail(string $filename, Throwable $e)
|
||||
{
|
||||
$message = $e->getPrevious()->getMessage();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue