3
According to the PHP documentation the exception InvalidArgumentException
should be used when an argument not expected by the application is received.
Second status code 400 and 422 on the website of Developer.mozila, it says:
400: The HTTP 400 Bad Request response status code indicates that the server cannot or will not process the request due to something that was understood as a client error (for example, misshapen request syntax, invalid request message framing or misleading routing request).
422: The HTTP 422 response code Unprocessable Entity indicates that the server understands the content type of the request entity, and the request syntax is correct, but it was not possible to process the present instructions.
Which status code
it would be correct to use an exception of the type InvalidArgumentException
?
if (is_null($attribute)) {
$message = sprintf('The attribute %s can not be null', $attribute);
throw new InvalidArgumentException($message, 400);
}
if (is_null($attribute)) {
$message = sprintf('The attribute %s can not be null', $attribute);
throw new InvalidArgumentException($message, 422);
}
Or is there another status code
more appropriate?