Attakinsky's avatar

Response with status code is failing.

I'm using:

  • Lumen 6x
  • Laradock (lastest)

I am returning a simple array, but it does not work as expected. Example:

return response()
            ->json(
                ['foo' => 'bar']
                , 409
            );

// returns {"data":[],"message":{},"status":409,"success":false}

But if I comment the status code, it works well:

return response()
            ->json(
                ['foo' => 'bar']
               // , 409
            );

// returns {"foo":"bar"}

At first I thought it was a JSON issue, but the normal response behaves the same.

return response(['foo' => 'bar'], 409);
// returns {"data":[],"message":{},"status":409,"success":false}

return response(['foo' => 'bar']);
// returns {"foo":"bar"}

In other projects I have used a template for response and it has always worked for me. Now, with this problem I stopped using it and the problem persists. I already cleaned cache and it still doesn't work. The template is like this:

[
       'data' => $data,
       'message' => $message,
       'status' => $code,
       'success' => false,
]

At the moment I can live without the status code, because I am in local development. But as soon as the API arrives with the people of the APP, they will surely require it.

0 likes
3 replies
bobbybouwmann's avatar

Have you tried a different status code to see if that works? 409 is a really specific code that the resource is busy and is not used often.

Attakinsky's avatar

Of course I tried with different state codes. I used this one for the example. But it happens with any other code.

bobbybouwmann's avatar

That doesn't make any sense to me. It's working fine for me at least. Do you have a like a middleware that is alternating the response?

Please or to participate in this conversation.