• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to show Custom View Error 429 Throttle

#1
Tongue 
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/libra...ttler.html
Thanks for help

Learning CI4 from my works, from errors and how to fix bugs in the community

Love CI & Thanks CI Teams

Reply

#2
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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#3
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...

Learning CI4 from my works, from errors and how to fix bugs in the community

Love CI & Thanks CI Teams

Reply

#4
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)
        {
        }


Learning CI4 from my works, from errors and how to fix bugs in the community

Love CI & Thanks CI Teams

Reply

#5
Dear,
Throttle can prevent DDos attack?
Thanks for help

Oh no, can not
Sorry about question ;-)

Learning CI4 from my works, from errors and how to fix bugs in the community

Love CI & Thanks CI Teams

Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.