Symfony JsonResponse忽略定义的HTTP代码,只响应200

I'm trying change HTTP code in Response but I always receive 200. the code below is resumed a lot with both tests:

$app->put('/hdc/v1/pagamento/{pagamento_id}', function($pagamento_id, Request $request) use ($app) {

    $pagamento = Pagamento::find($pagamento_id);

    return new JsonResponse(["message"=>"error"],400); // returns 200
}




$app->put('/hdc/v1/pagamento/{pagamento_id}', function($pagamento_id, Request $request) use ($app) {

//    $pagamento = Pagamento::find($pagamento_id);

    return new JsonResponse(["message"=>"error"],400); // returns 400
}

Interacting with the model, JsonResponse is impacted. Why?

Postman screenshot

Awkward!

My entity file Pagamento had

?>

in the file bottom. it was sending 200 code header when the Pagamento::find method was called.

I think you don't use the good method. See the silex doc :

<?php
$app->put('/hdc/v1/pagamento/{pag_id}', function($pag_id, Request $request) use ($app) {
return $app->json(array('message' => 'error'), 400);
});