Include headers in error message.

This commit is contained in:
James Cole
2022-03-06 16:03:52 +01:00
parent 2f55499f7d
commit 059bf32563
5 changed files with 34 additions and 4 deletions

View File

@@ -153,6 +153,12 @@ class Handler extends ExceptionHandler
$userData['id'] = auth()->user()->id; $userData['id'] = auth()->user()->id;
$userData['email'] = auth()->user()->email; $userData['email'] = auth()->user()->email;
} }
$headers = [];
if (request()->headers) {
$headers = request()->headers->all();
}
$data = [ $data = [
'class' => get_class($e), 'class' => get_class($e),
'errorMessage' => $e->getMessage(), 'errorMessage' => $e->getMessage(),
@@ -165,11 +171,12 @@ class Handler extends ExceptionHandler
'url' => request()->fullUrl(), 'url' => request()->fullUrl(),
'userAgent' => request()->userAgent(), 'userAgent' => request()->userAgent(),
'json' => request()->acceptsJson(), 'json' => request()->acceptsJson(),
'headers' => $headers,
]; ];
// create job that will mail. // create job that will mail.
$ipAddress = request()->ip() ?? '0.0.0.0'; $ipAddress = request()->ip() ?? '0.0.0.0';
$job = new MailError($userData, (string)config('firefly.site_owner'), $ipAddress, $data); $job = new MailError($userData, (string) config('firefly.site_owner'), $ipAddress, $data);
dispatch($job); dispatch($job);
parent::report($e); parent::report($e);

View File

@@ -60,7 +60,8 @@ class MailError extends Job implements ShouldQueue
$this->exception = $exceptionData; $this->exception = $exceptionData;
$debug = $exceptionData; $debug = $exceptionData;
unset($debug['stackTrace']); unset($debug['stackTrace']);
Log::error('Exception is: ' . json_encode($debug)); unset($debug['headers']);
Log::error(sprintf('Exception is: %s', json_encode($debug)));
} }
/** /**
@@ -81,7 +82,7 @@ class MailError extends Job implements ShouldQueue
$args, $args,
function (Message $message) use ($email) { function (Message $message) use ($email) {
if ('mail@example.com' !== $email) { if ('mail@example.com' !== $email) {
$message->to($email, $email)->subject((string)trans('email.error_subject')); $message->to($email, $email)->subject((string) trans('email.error_subject'));
} }
} }
); );

View File

@@ -97,6 +97,7 @@ return [
'error_github_html' => 'If you prefer, you can also open a new issue on <a href="https://github.com/firefly-iii/firefly-iii/issues">GitHub</a>.', 'error_github_html' => 'If you prefer, you can also open a new issue on <a href="https://github.com/firefly-iii/firefly-iii/issues">GitHub</a>.',
'error_github_text' => 'If you prefer, you can also open a new issue on https://github.com/firefly-iii/firefly-iii/issues.', 'error_github_text' => 'If you prefer, you can also open a new issue on https://github.com/firefly-iii/firefly-iii/issues.',
'error_stacktrace_below' => 'The full stacktrace is below:', 'error_stacktrace_below' => 'The full stacktrace is below:',
'error_headers' => 'The following headers may also be relevant:',
// report new journals // report new journals
'new_journals_subject' => 'Firefly III has created a new transaction|Firefly III has created :count new transactions', 'new_journals_subject' => 'Firefly III has created a new transaction|Firefly III has created :count new transactions',

View File

@@ -27,7 +27,6 @@
<p style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;"> <p style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;">
{{ trans('email.error_ip', { ip: ip }) }} (<a href="https://ipinfo.io/{{ ip }}/json?token={{ token }}">info</a>)<br /> {{ trans('email.error_ip', { ip: ip }) }} (<a href="https://ipinfo.io/{{ ip }}/json?token={{ token }}">info</a>)<br />
{{ trans('email.error_url', {url :url }) }}<br /> {{ trans('email.error_url', {url :url }) }}<br />
{{ trans('email.error_user_agent', {userAgent: userAgent }) }}
</p> </p>
<p style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;"> <p style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;">
@@ -42,4 +41,16 @@
<p style="font-family: monospace;font-size:11px;color:#aaa"> <p style="font-family: monospace;font-size:11px;color:#aaa">
{{ stackTrace|nl2br }} {{ stackTrace|nl2br }}
</p> </p>
<p style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;">
{{ trans('email.error_headers') }}
</p>
<p style="font-family: monospace;font-size:11px;color:#aaa">
{% for key, header in headers %}
{% if (key != 'cookie') and header[0] != '' %}
- {{ key }}: {{ header[0] }}<br>
{% endif %}
{% endfor %}
</p>
{% include 'emails.footer-html' %} {% include 'emails.footer-html' %}

View File

@@ -24,4 +24,14 @@
{{ trans('email.error_stacktrace_below')|raw }} {{ trans('email.error_stacktrace_below')|raw }}
{{ stackTrace|raw }} {{ stackTrace|raw }}
{{ trans('email.error_headers') }}
{% for key, header in headers %}
{% if (key != 'cookie') and header[0] != '' %}
- {{ key }}: {{ header[0] }}
{% endif %}
{% endfor %}
{% include 'emails.footer-text' %} {% include 'emails.footer-text' %}