[3.12.3] Wrong status code returned with response

Hi guys,

I’ve spent a few hours searching the forums, Stack Overflow and all the usual spots and I can almost guarantee that this issue is a rather strange one.

Everything worked normally until a few hours ago. No matter the resource requested, I’m always getting a 200 status code.

For example:

$app->get('/test-json', function (Request $request, Response $response, array $args = []) {
    $response = $response->withJson(['message' => 'error'], 400);    
    return $response;
});

// outputs {"message": "error} with status => 200

I’ve also disabled all middleware to be sure and even requested a nonexistent resource test-json-b to check. expecting a 404, but the same happens here.

I’m running Slim 3.12.3 (upgraded from 3.0.0 a moment a go) on a macOS Catalina.

i’d appreciate a second pair of eyes.

That code works perfectly for me and I get a 400 response, so the error is seemingly elsewhere. Have you tried disabling all of your other routes?

If you require Slim 3.0.0 does it work properly again?

1 Like

@tflight thanks for checking in. I was actually running Slim 3.0.0 when the issue first started. i figured I’d try and upgrade it to see if anything changes, but no. Let me try disabling all other routes to check.

Wow. I disabled all other routes and things are back to normal. i’ll isolate each route to spot the faulty one.

Thanks a lot! This saved me so much headache.

Play with the order of routes as well as you might have multiple routes that could match, but the first match will win. :slight_smile:

Funny enough, things work well when I move the code above out of the faulty route into another. I’m sure some dependency is playing tricks on me, but that’s a fight for another day. I’m happy things are working.

Thanks again for the great help.