Skip to content
Advertisement

error log truncated in laravel 5.3

i have this entry in my laravel 5.3 log

2016-12-22 17:23:37] local.ERROR: GuzzleHttpExceptionClientException: Client error: POST https://api.sparkpost.com/api/v1/transmissions resulted in a 400 Bad Request response: { “errors”: [ { “message”: “Message generation rejected”, “description”: “recipient address suppressed due to customer p (truncated…)

why does it truncate an important error message? now i cannot figure out what is going wrong…

Advertisement

Answer

The truncating is done by the Guzzle library. It only shows the first 120 characters of the response. I am assuming this is because responses could potentially be very long.

If you would like to see the full message, you should be able to customize how guzzle exceptions are handled.

Update the report() method in your app/Exceptions/Handler.php to something like:

public function report(Exception $exception)
{
    // this is from the parent method
    if ($this->shouldntReport($exception)) {
        return;
    }

    // this is from the parent method
    try {
        $logger = $this->container->make(PsrLogLoggerInterface::class);
    } catch (Exception $ex) {
        throw $exception; // throw the original exception
    }

    // this is the new custom handling of guzzle exceptions
    if ($exception instanceof GuzzleHttpExceptionRequestException) {
        // get the full text of the exception (including stack trace),
        // and replace the original message (possibly truncated),
        // with the full text of the entire response body.
        $message = str_replace(
            rtrim($exception->getMessage()),
            (string) $exception->getResponse()->getBody(),
            (string) $exception
        );

        // log your new custom guzzle error message
        return $logger->error($message);
    }

    // make sure to still log non-guzzle exceptions
    $logger->error($exception);
}

Note: this is done in the report method, so it only affects what is written to the log. If the exception is dumped to the terminal or to the browser, it will still show the truncated message.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement