Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 4 always returns HTTP status code 200

I have below code in error.php, which is triggered using App::abort(404, $error) in my controller. Still my response status code is 200(ok). I tried with various error codes like 400, 403

// NotFoundException handler
App::error(function(NotFoundException $e)
{
    $default_message = 'The requested resource was not found';

    return Response::json(array(
        'error' => $e->getMessage() ?: $default_message,
    ), 404);
 });
like image 880
Saravana Kumar Avatar asked Dec 08 '22 15:12

Saravana Kumar


1 Answers

For anyone still googling this problem:

I was struggling with this problem for hours. For me the problem was caused by an issue with one of my controllers.

Check all of your controllers and make sure there are no spaces in front of the <?php tag. The <?php tag should be the very first thing in the file. A single space in front of the <?php tag in any of your controllers that are routed as such:

Route::controller('example', 'ExampleController');

Will cause all status codes to be 200.

like image 70
knews12 Avatar answered Dec 11 '22 09:12

knews12