第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Symfony 5 更新后 Laravel 7 電子郵件異常中斷

Symfony 5 更新后 Laravel 7 電子郵件異常中斷

PHP
猛跑小豬 2022-10-28 16:23:06
我已經(jīng)升級(jí)到 Laravel 7.1,現(xiàn)在有了 Symfony 5,這些類不再存在:use Symfony\Component\Debug\Exception\FlattenException;use Symfony\Component\Debug\ExceptionHandler as SymfonyExceptionHandler;我在我的 app\Exceptions\Handler.php 文件中使用它們來(lái)在拋出異常時(shí)發(fā)送電子郵件通知,并且它們?cè)?Laravel 6 中運(yùn)行良好,但是當(dāng)我從 6.x 升級(jí)到 7.1.2 時(shí)中斷了,它也升級(jí)到了 Symfony 5。我用這些替換了上述類:use Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer;use Symfony\Component\ErrorHandler\Exception\FlattenException;然后替換了這個(gè):$e = FlattenException::create($exception);$handler = new SymfonyExceptionHandler();$html = $handler->getHtml($e);有了這個(gè):$e = FlattenException::create($exception);$handler = new HtmlErrorRenderer();$content = $handler->getBody($e);這可行,但現(xiàn)在我不再像以前那樣在電子郵件中獲取調(diào)試內(nèi)容,而是收到一條更基本的錯(cuò)誤消息,因?yàn)樗轻槍?duì)公眾的。您可以在此處查看不同格式的示例: https ://symfony.com/doc/current/controller/error_pages.html我確信我缺少一些簡(jiǎn)單的東西,但我還沒(méi)有想出如何讓它像我在升級(jí)之前得到的那樣向我發(fā)送詳細(xì)的異常數(shù)據(jù)。有什么建議么?
查看完整描述

3 回答

?
繁星coding

TA貢獻(xiàn)1797條經(jīng)驗(yàn) 獲得超4個(gè)贊

下面是我最終用來(lái)在異常通知電子郵件中獲得我想要的結(jié)果的代碼。我之前缺少的主要部分是我沒(méi)有將真實(shí)值傳遞給 HtmlErrorRender 類來(lái)引發(fā)調(diào)試標(biāo)志。更正后的行如下所示:


new HtmlErrorRenderer(true);

這是我現(xiàn)在用于 app/Exceptions/Handler.php 文件的完整代碼


<?php


namespace App\Exceptions;


use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;

use Log;

use Throwable;

use Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer;

use Symfony\Component\ErrorHandler\Exception\FlattenException;


class Handler extends ExceptionHandler

{

    /**

     * A list of the exception types that are not reported.

     *

     * @var array

     */

    protected $dontReport = [

    ];


    /**

     * A list of the inputs that are never flashed for validation exceptions.

     *

     * @var array

     */

    protected $dontFlash = [

        'password',

        'password_confirmation',

    ];


    /**

     * Report or log an exception.

     *

     * @param  \Throwable  $exception

     * @return void

     *

     * @throws \Exception

     */

    public function report(Throwable $exception)

    {

        if ($this->shouldReport($exception)) {

            $this->sendEmail($exception); // sends an email

        }

        parent::report($exception);

    }


    /**

     * Render an exception into an HTTP response.

     *

     * @param  \Illuminate\Http\Request  $request

     * @param  \Throwable  $exception

     * @return \Symfony\Component\HttpFoundation\Response

     *

     * @throws \Throwable

     */

    public function render($request, Throwable $exception)

    {

        if ($exception instanceof \Illuminate\Session\TokenMismatchException) {  //https://gist.github.com/jrmadsen67/bd0f9ad0ef1ed6bb594e

            return redirect()

                ->back()

                ->withInput($request->except('password'))

                ->with('errorMessage', 'This form has expired due to inactivity. Please try again.');

        }


        return parent::render($request, $exception);

    }


    /**

     * Sends an email to the developer about the exception.

     *

     * @return void

     */

    public function sendEmail(Throwable $exception)

    {

        try {

            $e = FlattenException::create($exception);

            $handler = new HtmlErrorRenderer(true); // boolean, true raises debug flag...

            $css = $handler->getStylesheet();

            $content = $handler->getBody($e);


            \Mail::send('emails.exception', compact('css','content'), function ($message) {

                $message

                    ->to('youremailhere@gmail.com')

                    ->subject('Exception: ' . \Request::fullUrl())

                ;

            });

        } catch (Throwable $ex) {

            Log::error($ex);

        }

    }

}

$css 和 $content 被傳遞到 resources/views/emails/exception.blade.php 的視圖中。我在該文件中的代碼如下:


<!DOCTYPE html>

<html>

    <head>

        <meta charset="UTF-8" />

        <style>{!! $css ?? '' !!}</style>

    </head>

    <body>

        {!! $content ?? '' !!}

    </body>

</html>


查看完整回答
反對(duì) 回復(fù) 2022-10-28
?
交互式愛(ài)情

TA貢獻(xiàn)1712條經(jīng)驗(yàn) 獲得超3個(gè)贊

測(cè)試答案后,我得到一些錯(cuò)誤“解析到異常類”,所以如果你使用 Laravel 7,你需要使用“create”的“createFromThrowable”代替“create”來(lái)與 Throwable 對(duì)象兼容。



查看完整回答
反對(duì) 回復(fù) 2022-10-28
?
楊魅力

TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超6個(gè)贊

要獲得完整的 html 響應(yīng),只需使用:


$html = ExceptionHandler::convertExceptionToResponse($e);

這是完整的 Handler.php 代碼


<?php


namespace App\Exceptions;


use Log;

use Mail;

use Exception;

use Throwable;

use App\Mail\ErrorNotification;

use Illuminate\Database\Eloquent\ModelNotFoundException;

use Symfony\Component\HttpKernel\Exception\HttpException;

use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;

use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;



class Handler extends ExceptionHandler

{


    /**

     * A list of the exception types that should not be reported.

     *

     * @var array

     */

    protected $dontReport = [

        HttpException::class,

        ModelNotFoundException::class,

    ];


    /**

     * Report or log an exception.

     *

     * This is a great spot to send exceptions to Sentry, Bugsnag, etc.

     *

     * @param  \Exception  $e

     * @return void

     */

    public function report(Throwable $e)

    {

        if ($this->shouldReport($e)) {

            $this->sendEmail($e);

        }


        return parent::report($e);

    }


    /**

     * Render an exception into an HTTP response.

     *

     * @param  \Illuminate\Http\Request  $request

     * @param  \Exception  $e

     * @return \Illuminate\Http\Response

     */

    public function render($request, Throwable $e)

    {

        if ($e instanceof ModelNotFoundException) {

            $e = new NotFoundHttpException($e->getMessage(), $e);

        }


        return parent::render($request, $e);

    }



    public function sendEmail(Throwable $e)

    {

        try {


            $html = ExceptionHandler::convertExceptionToResponse($e);


            Mail::to('youremailhere@gmail.com')->send(new ErrorNotification($html));


        } catch (Exception $ex) {

            Log::error($ex);

        }

    }


}


查看完整回答
反對(duì) 回復(fù) 2022-10-28
  • 3 回答
  • 0 關(guān)注
  • 149 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)