Framework: #5.7 BUG# Laravel Expcetion repeat response show

Created on 18 Sep 2018  ·  16Comments  ·  Source: laravel/framework

  • Laravel Version: 5.7
  • PHP Version: 7.2

Description:

result is invalid json, repeat show

Steps To Reproduce:

1、composer create-project --prefer-dist laravel/laravel blog
2、cd blog && php artisan serve
3、edit app\Http\Kernel.php file,write in api configure

'api' => [
    ...,
    'json.response', // notice, this middleware is not exists,because these can to reproduce this error
]

4、edit route\api.php, add content

Route::get('/test', function () {
    return 'reproduce error';
});

5、used postman add headers Accept: application/json and get http://localhost:8000/api/test
6、result show is invalid json,this result repeat response show

{
    "message": "Class json.response does not exist",
    "exception": "ReflectionException",
    "file": "/Users/yyj/Docker/wwwroot/blog/vendor/laravel/framework/src/Illuminate/Container/Container.php",
    "line": 767,
    "trace": [
        {
            "file": "/Users/yyj/Docker/wwwroot/blog/vendor/laravel/framework/src/Illuminate/Container/Container.php",
            "line": 767,
            "function": "__construct",
            "class": "ReflectionClass",
            "type": "->"
        },
        {
            "file": "/Users/yyj/Docker/wwwroot/blog/vendor/laravel/framework/src/Illuminate/Container/Container.php",
            "line": 646,
            "function": "build",
            "class": "Illuminate\\Container\\Container",
            "type": "->"
        },
        {
            "file": "/Users/yyj/Docker/wwwroot/blog/vendor/laravel/framework/src/Illuminate/Container/Container.php",
            "line": 601,
            "function": "resolve",
            "class": "Illuminate\\Container\\Container",
            "type": "->"
        },
        // more something ....
    ]
}{
    "message": "Class json.response does not exist",
    "exception": "ReflectionException",
    "file": "/Users/yyj/Docker/wwwroot/blog/vendor/laravel/framework/src/Illuminate/Container/Container.php",
    "line": 767,
    "trace": [
        {
            "file": "/Users/yyj/Docker/wwwroot/blog/vendor/laravel/framework/src/Illuminate/Container/Container.php",
            "line": 767,
            "function": "__construct",
            "class": "ReflectionClass",
            "type": "->"
        },
        {
            "file": "/Users/yyj/Docker/wwwroot/blog/vendor/laravel/framework/src/Illuminate/Container/Container.php",
            "line": 646,
            "function": "build",
            "class": "Illuminate\\Container\\Container",
            "type": "->"
        },
        {
            "file": "/Users/yyj/Docker/wwwroot/blog/vendor/laravel/framework/src/Illuminate/Container/Container.php",
            "line": 601,
            "function": "resolve",
            "class": "Illuminate\\Container\\Container",
            "type": "->"
        },
        // more something ....
    ]
}

Most helpful comment

I want to know how to solve this problem

If you create a json.response middleware - that would solve it?

All 16 comments

@TBlindaruk @taylorotwell @GrahamCampbell

I don't know, what happened to this?

Its not really invalid JSON though - seems valid to me, although it is duplicated, but that's not really an issue is it...?

@laurencei because it is duplicated, So this should be a problem,I want to know how to solve this problem. It has bothered me for one night. my god...

I want to know how to solve this problem

If you create a json.response middleware - that would solve it?

@laurencei yes, can be solved after creation, but this problem seems to be in the framework

@laurencei I want to solve this problem elegantly.

@laurencei Can you add a bug labels on this issuse ?

Man, try to solve the problem yourself no need to be rude...

I just tried this on a fresh laravel installation and could not replicate. I get just the one error message.

Must be something with your local setup. Perhaps try using a full web server rather than artisan serve

{
    "message": "Class json.response does not exist",
    "exception": "ReflectionException",
    "file": "/home/vagrant/www/dev/devbox1/vendor/laravel/framework/src/Illuminate/Container/Container.php",
    "line": 767,
    "trace": [
        {
            "file": "/home/vagrant/www/dev/devbox1/vendor/laravel/framework/src/Illuminate/Container/Container.php",
            "line": 767,
            "function": "__construct",
            "class": "ReflectionClass",
            "type": "->"
        },
        {
            "file": "/home/vagrant/www/dev/devbox1/vendor/laravel/framework/src/Illuminate/Container/Container.php",
            "line": 646,
            "function": "build",
            "class": "Illuminate\\Container\\Container",
            "type": "->"
        },
        {
            "file": "/home/vagrant/www/dev/devbox1/vendor/laravel/framework/src/Illuminate/Container/Container.php",
            "line": 601,
            "function": "resolve",
            "class": "Illuminate\\Container\\Container",
            "type": "->"
        },
        {
            "file": "/home/vagrant/www/dev/devbox1/vendor/laravel/framework/src/Illuminate/Foundation/Application.php",
            "line": 733,
            "function": "make",
            "class": "Illuminate\\Container\\Container",
            "type": "->"
        },
        {
            "file": "/home/vagrant/www/dev/devbox1/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 140,
            "function": "make",
            "class": "Illuminate\\Foundation\\Application",
            "type": "->"
        },
        {
            "file": "/home/vagrant/www/dev/devbox1/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
            "line": 53,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/vagrant/www/dev/devbox1/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php",
            "line": 57,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/vagrant/www/dev/devbox1/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 151,
            "function": "handle",
            "class": "Illuminate\\Routing\\Middleware\\ThrottleRequests",
            "type": "->"
        },
        {
            "file": "/home/vagrant/www/dev/devbox1/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
            "line": 53,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/vagrant/www/dev/devbox1/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 104,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/vagrant/www/dev/devbox1/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 681,
            "function": "then",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/vagrant/www/dev/devbox1/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 656,
            "function": "runRouteWithinStack",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/home/vagrant/www/dev/devbox1/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 622,
            "function": "runRoute",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/home/vagrant/www/dev/devbox1/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 611,
            "function": "dispatchToRoute",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/home/vagrant/www/dev/devbox1/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
            "line": 176,
            "function": "dispatch",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/home/vagrant/www/dev/devbox1/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
            "line": 30,
            "function": "Illuminate\\Foundation\\Http\\{closure}",
            "class": "Illuminate\\Foundation\\Http\\Kernel",
            "type": "->"
        },
        {
            "file": "/home/vagrant/www/dev/devbox1/vendor/fideloper/proxy/src/TrustProxies.php",
            "line": 57,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/vagrant/www/dev/devbox1/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 151,
            "function": "handle",
            "class": "Fideloper\\Proxy\\TrustProxies",
            "type": "->"
        },
        {
            "file": "/home/vagrant/www/dev/devbox1/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
            "line": 53,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/vagrant/www/dev/devbox1/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php",
            "line": 31,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/vagrant/www/dev/devbox1/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 151,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest",
            "type": "->"
        },
        {
            "file": "/home/vagrant/www/dev/devbox1/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
            "line": 53,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/vagrant/www/dev/devbox1/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php",
            "line": 31,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/vagrant/www/dev/devbox1/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 151,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest",
            "type": "->"
        },
        {
            "file": "/home/vagrant/www/dev/devbox1/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
            "line": 53,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/vagrant/www/dev/devbox1/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php",
            "line": 27,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/vagrant/www/dev/devbox1/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 151,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize",
            "type": "->"
        },
        {
            "file": "/home/vagrant/www/dev/devbox1/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
            "line": 53,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/vagrant/www/dev/devbox1/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php",
            "line": 62,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/vagrant/www/dev/devbox1/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 151,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode",
            "type": "->"
        },
        {
            "file": "/home/vagrant/www/dev/devbox1/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
            "line": 53,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/vagrant/www/dev/devbox1/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 104,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/vagrant/www/dev/devbox1/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
            "line": 151,
            "function": "then",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/vagrant/www/dev/devbox1/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
            "line": 116,
            "function": "sendRequestThroughRouter",
            "class": "Illuminate\\Foundation\\Http\\Kernel",
            "type": "->"
        },
        {
            "file": "/home/vagrant/www/dev/devbox1/public/index.php",
            "line": 55,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Kernel",
            "type": "->"
        }
    ]
}

emm. It is a bug, framework thought it is not in cli mode while running php artisan server (run as php -S) while getting an http request.

    public function runningInConsole()
    {
        return php_sapi_name() === 'cli' || php_sapi_name() === 'phpdbg';
    }

But the sapi name of php -S is cli-server, runningInConsole gets false.
Fix: https://github.com/laravel/framework/pull/25696

@ipengxh thanks for you

, framework thought it is not in cli mode while running php artisan server (run as php -S) while getting an http request.

But the http request is NOT running in CLI mode - that is correct. We dont want HTTP Requests to think they are in CLI mode (regardless of the server underneath)?

I dont understand why you think this is a bug? Are you able to elaborate further?

If you don't want to run in cli mode, why do you have the php artisan serve command? why isn't it perfect if it's provided?

Because php artisan serve is for the server to run your application on.

The actual HTTP request itself is not a CLI call - it is supposed to run in HTTP mode. CLI mode is meant for when you run artisan commands against your application.

All right,I don't think I have anything to say, I just want to be able to quickly develop and test Laravel applications without having to set up an environment like Nginx or Apache

Was this page helpful?
0 / 5 - 0 ratings