Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 3 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ResponseException | |
0.00% |
0 / 3 |
|
0.00% |
0 / 2 |
6 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getResponse | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Rest; |
| 4 | |
| 5 | /** |
| 6 | * This is an exception class that wraps a Response and extends |
| 7 | * HttpException. It is used when a particular response type |
| 8 | * (whatever the HTTP status code) is treated as an exceptional output |
| 9 | * in your API, and you want to be able to throw it from wherever you |
| 10 | * are and immediately halt request processing. It can also be used |
| 11 | * to customize the standard 3xx or 4xx error Responses returned by |
| 12 | * the standard HttpException, for example to add custom headers. |
| 13 | * |
| 14 | * @newable |
| 15 | * @since 1.36 |
| 16 | */ |
| 17 | class ResponseException extends HttpException { |
| 18 | |
| 19 | /** |
| 20 | * The wrapped Response. |
| 21 | * @var ResponseInterface |
| 22 | */ |
| 23 | private $response; |
| 24 | |
| 25 | /** |
| 26 | * @stable to call |
| 27 | * |
| 28 | * @param ResponseInterface $response The wrapped Response |
| 29 | */ |
| 30 | public function __construct( ResponseInterface $response ) { |
| 31 | parent::__construct( 'Response', $response->getStatusCode() ); |
| 32 | $this->response = $response; |
| 33 | } |
| 34 | |
| 35 | public function getResponse(): Response { |
| 36 | // TODO: Allow this method to return a ResponseInterface. |
| 37 | // But that would be a breaking change. |
| 38 | return Response::cast( $this->response ); |
| 39 | } |
| 40 | } |