At times I return, at server level, some extra information alongside with a HTTP 404
For example, instead of returning just a 404
, which can puzzle my client whether the routing is correct or not, it will also receive something like
the identifier 'abc' is unknown
I usually set the content type to text/plain
and return some text in the Content
Another alternative is to set the ReasonPhrase
instead.
Which one is the best way / convention? Set Content
or set ReasonPhrase
?
The error message should be put in response body ( Content
), not in response Reason Phrase
.
According to RFC 2616 :
The Reason-Phrase is intended to give a short textual description of the Status-Code...The client is not required to examine or display the Reason-Phrase.
Some explanation:
You can use custom error responses and overrides the 404 and any other error you want visit here Spring MVC: How to return custom 404 errorpages?
Create a view and set this code in app/Exception/Handler.php :
/*Render an exception into a response. * * @param \\Illuminate\\Http\\Request $request * @param \\Exception $e * @return \\Illuminate\\Http\\Response
*/
public function render($request, Exception $e)
{
if($e instanceof NotFoundHttpException)
{
return response()->view('missing', [], 404);
}
return parent::render($request, $e);
}
Set this use to get it working :
use Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException;
For more info you can visit
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.