Debian Codegraph @

includes/Rest/ResponseException.php

raw symbols SCIP
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 /**
36 * @return Response
37 */
38 public function getResponse(): Response {
39 // TODO: Allow this method to return a ResponseInterface.
40 // But that would be a breaking change.
41 return Response::cast( $this->response );
42 }
43 }