mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 08:44:46 +02:00
Use new context to log the request id
This commit is contained in:
parent
03b1fc4636
commit
796a236ef4
@ -5,6 +5,7 @@ namespace App\Exceptions\Http\Connection;
|
||||
use Illuminate\Http\Response;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use App\Exceptions\DisplayException;
|
||||
use Illuminate\Support\Facades\Context;
|
||||
|
||||
/**
|
||||
* @method \GuzzleHttp\Exception\GuzzleException getPrevious()
|
||||
@ -30,6 +31,8 @@ class DaemonConnectionException extends DisplayException
|
||||
$response = method_exists($previous, 'getResponse') ? $previous->getResponse() : null;
|
||||
$this->requestId = $response?->getHeaderLine('X-Request-Id');
|
||||
|
||||
Context::add('request_id', $this->requestId);
|
||||
|
||||
if ($useStatusCode) {
|
||||
$this->statusCode = is_null($response) ? $this->statusCode : $response->getStatusCode();
|
||||
// There are rare conditions where daemon encounters a panic condition and crashes the
|
||||
@ -63,17 +66,6 @@ class DaemonConnectionException extends DisplayException
|
||||
parent::__construct($message, $previous, $level);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the default reporting method for DisplayException by just logging immediately
|
||||
* here and including the specific X-Request-Id header that was returned by the call.
|
||||
*/
|
||||
public function report()
|
||||
{
|
||||
logger()->{$this->getErrorLevel()}($this->getPrevious(), [
|
||||
'request_id' => $this->requestId,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the HTTP status code for this exception.
|
||||
*/
|
||||
@ -81,9 +73,4 @@ class DaemonConnectionException extends DisplayException
|
||||
{
|
||||
return $this->statusCode;
|
||||
}
|
||||
|
||||
public function getRequestId(): ?string
|
||||
{
|
||||
return $this->requestId;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user