Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
60.00% covered (warning)
60.00%
3 / 5
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
TooManyRequestsException
60.00% covered (warning)
60.00%
3 / 5
0.00% covered (danger)
0.00%
0 / 2
3.58
0.00% covered (danger)
0.00%
0 / 1
 __construct
75.00% covered (warning)
75.00%
3 / 4
0.00% covered (danger)
0.00%
0 / 1
2.06
 getRetryAfter
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2declare(strict_types=1);
3
4namespace App\Http\Exception;
5
6use Cake\Http\Exception\HttpException;
7use Throwable;
8
9class TooManyRequestsException extends HttpException
10{
11    protected int $_defaultCode = 429;
12    protected ?int $retryAfter;
13
14    /**
15     * Constructor
16     *
17     * @param string|null $message If no message is given 'Too Many Requests' will be the message
18     * @param int|null $code Status code, defaults to 429
19     * @param int|null $retryAfter The number of seconds after which the client should retry
20     * @param \Throwable|null $previous The previous exception.
21     */
22    public function __construct(
23        ?string $message = null,
24        ?int $code = null,
25        ?int $retryAfter = null,
26        ?Throwable $previous = null,
27    ) {
28        $this->retryAfter = $retryAfter;
29        if (empty($message)) {
30            $message = __('Too Many Requests');
31        }
32        parent::__construct($message, $code, $previous);
33    }
34
35    /**
36     * Get the retry after value.
37     *
38     * @return int|null
39     */
40    public function getRetryAfter(): ?int
41    {
42        return $this->retryAfter;
43    }
44}