CodeIgniter Forums
set exception 400 to 404 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: set exception 400 to 404 (/showthread.php?tid=90915)



set exception 400 to 404 - mylastof - 05-21-2024

I have error BadRequest with code 400
how to handle it to force show as 404?

can you help?

CodeIgniter\HTTP\Exceptions\BadRequestException


RE: set exception 400 to 404 - 68thorby68 - 08-26-2024

(05-21-2024, 06:54 PM)mylastof Wrote: I have error BadRequest with code 400
how to handle it to force show as 404?

can you help?

CodeIgniter\HTTP\Exceptions\BadRequestException

If you are controlling the response yourself, e.g. in your controller, you can return specific HTTP response (below), however if a server is genuinely returning a 400 error I personally would not want to change this, instead take i'd try to take the appropriate action based on the server response.
PHP Code:
return $this->response->setStatusCode(404);