简体   繁体   English

php laravel-try-catch不起作用

[英]php laravel - try-catch not working

my api controller: 我的api控制器:

$POST /api/member/logout

public function post_logout(){
    try{
        member::logout();
        return Response::json([], 200);
    }catch(Exception $e){
        print_r($e);
        return Response::json($e, 500);
    }
}

and my model 和我的模特

public static function logout(){
    if(!Auth::check()){
        throw new Exception('not_logged');
    }

    Auth::logout();
}

It is returning status 200 but never ends loading (18.3mb loaded and counting...) 它返回状态200,但永不结束加载(已加载18.3mb并正在计数...)

You are printing Exception object before json response with status 500, so PHP automatically sends response with status code 200. 您要在状态为500的json响应之前打印Exception对象,因此PHP会自动发送状态为200的响应。

As for huge never-ending response, I'm not sure since I don't know Laravael at all, but I suspect, that somewhere you are (or this framework is) dumping an object that references itself. 至于巨大的永无休止的响应,我不确定,因为我根本不了解Laravael,但我怀疑您正在某个位置(或此框架)转储引用自己的对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM