Lumen-framework: http response status code always return 200

Created on 10 Dec 2019  Â·  4Comments  Â·  Source: laravel/lumen-framework

  • Lumen Version: Lumen (6.2.0) (Laravel Components ^6.0)
  • Laravel Version: #.#.#
  • PHP Version: 7.3.11(windows)
  • Database Driver & Version:

Description:

I installed lumen by composer
global require "laravel/lumen-installer"

add the code in reoutes/web.php file
$router->get('/', function () use ($router) { return response()->json(['test' => 1], 500); });

I think http response status code will return 500 but always return 200
image

I tested a nonexistent url http response still returns code 200
image

Please tell me how to set the http status code, thanks

Steps To Reproduce:

edit code in routes/web.php
$router->get('/', function () use ($router) { return response()->json(['test' => 1], 500); });

Most helpful comment

I had the same issue on my app (Lumen 6.4) and believe me or not the issue was a extra blank line at the top of my app.php.

<?php
require_once __DIR__.'/helpers.php';
require_once __DIR__.'/../vendor/autoload.php';

So I just removed it:

<?php
require_once __DIR__.'/helpers.php';
require_once __DIR__.'/../vendor/autoload.php';

And everything was working like a charm!!

All 4 comments

Hi there,

Thanks for reporting but it looks like this is a question which can be asked on a support channel. Please only use this issue tracker for reporting bugs with the library itself. If you have a question on how to use functionality provided by this repo you can try one of the following channels:

However, this issue will not be locked and everyone is still free to discuss solutions to your problem!

Thanks.

I had the same issue on my app (Lumen 6.4) and believe me or not the issue was a extra blank line at the top of my app.php.

<?php
require_once __DIR__.'/helpers.php';
require_once __DIR__.'/../vendor/autoload.php';

So I just removed it:

<?php
require_once __DIR__.'/helpers.php';
require_once __DIR__.'/../vendor/autoload.php';

And everything was working like a charm!!

@dericlima Thanks, in my case, the extra blank line was in the routes/web.php

How did you catch this empty error?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

timrogers picture timrogers  Â·  3Comments

patrikengborg picture patrikengborg  Â·  3Comments

soderluk picture soderluk  Â·  3Comments

jampack picture jampack  Â·  3Comments

jairobjunior picture jairobjunior  Â·  4Comments