CodeIgniter Forums
How to show Custom View Error 429 Throttle - 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: How to show Custom View Error 429 Throttle (/showthread.php?tid=77775)



How to show Custom View Error 429 Throttle - nc03061981 - 10-16-2020

Dear,
I use Throttle to limit POST in second
So, how to show custom View with this error 429
- Detail here https://codeigniter.com/user_guide/libraries/throttler.html
Thanks for help


RE: How to show Custom View Error 429 Throttle - InsiteFX - 10-16-2020

You can try to copy the error_404.php to a new error_429.php in the Views\errors folder
Changing all internal 404 stuff to 429 - To Many Requests.

Or try to use a try catch block and see if you can catch the exception error.


RE: How to show Custom View Error 429 Throttle - nc03061981 - 10-16-2020

It's here
PHP Code:
if ($response->getStatusCode() == 429)
{


Thanks...

(10-16-2020, 08:09 PM)InsiteFX Wrote: You can try to copy the error_404.php to a new error_429.php in the Views\errors folder
Changing all internal 404 stuff to 429 - To Many Requests.

Or try to use a try catch block and see if you can catch the exception error.

Thanks, i am trying...


RE: How to show Custom View Error 429 Throttle - nc03061981 - 10-16-2020

PHP Code:
<?php namespace App\Filters;

use 
CodeIgniter\Filters\FilterInterface;
use 
CodeIgniter\HTTP\RequestInterface;
use 
CodeIgniter\HTTP\ResponseInterface;
use 
Config\Services;

class 
Throttle implements FilterInterface
{
        
/**
         * This is a demo implementation of using the Throttler class
         * to implement rate limiting for your application.
         *
         * @param RequestInterface|\CodeIgniter\HTTP\IncomingRequest $request
         * @param array|null                                         $arguments
         *
         * @return mixed
         */
        
public function before(RequestInterface $request$arguments null)
        {
                
$throttler Services::throttler();

                
// Restrict an IP address to no more
                // than 1 request per second across the
                // entire site.
                
if ($throttler->check($request->getIPAddress(), 5MINUTE) === false)
                {
                    die(
view('/errors/html/error_429', ['url' => current_url()]));
                    return 
Services::response()->setStatusCode(429);
                }
        }

        
//--------------------------------------------------------------------

        /**
         * We don't have anything to do here.
         *
         * @param RequestInterface|\CodeIgniter\HTTP\IncomingRequest $request
         * @param ResponseInterface|\CodeIgniter\HTTP\Response       $response
         * @param array|null                                         $arguments
         *
         * @return mixed
         */
        
public function after(RequestInterface $requestResponseInterface $response$arguments null)
        {
        }




RE: How to show Custom View Error 429 Throttle - nc03061981 - 10-17-2020

Dear,
Throttle can prevent DDos attack?
Thanks for help

Oh no, can not
Sorry about question ;-)