Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

JCKN123's avatar

The HTTP status code "0" is not valid

I received an error in this line

return response()->json( $api->errorsArray(),'error');

Error will be

InvalidArgumentException: The HTTP status code "0" is not valid. in /var/www/html/vendor/symfony/http-foundation/Response.php:462

0 likes
1 reply
tykus's avatar
tykus
Best Answer
Level 104

The second parameter to json() should be a valid status code, e.g. 2xx, 4xx etc. It defaults to 200, so pick an appropriate one in the case of an error.

If you wanted to have an errors key then:

return response()->json(['errors' => $api->errorsArray()], 422);

Please or to participate in this conversation.