简体   繁体   中英

php laravel - try-catch not working

my api controller:

$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...)

You are printing Exception object before json response with status 500, so PHP automatically sends response with status code 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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