aboutsummaryrefslogtreecommitdiffstats
path: root/includes/Rest/Module/Module.php
diff options
context:
space:
mode:
authorbpirkle <bpirkle@wikimedia.org>2024-09-16 11:39:02 -0500
committerbpirkle <bpirkle@wikimedia.org>2024-09-16 18:09:12 -0500
commit90494183bba46518a496275c12cdd126d6065a58 (patch)
tree578faa529c43c1a073002bfd20853e0baba37a37 /includes/Rest/Module/Module.php
parentd8efb20b3fdef7a6959f787b7da51a11feec2ff1 (diff)
downloadmediawikicore-90494183bba46518a496275c12cdd126d6065a58.tar.gz
mediawikicore-90494183bba46518a496275c12cdd126d6065a58.zip
REST: add restbase compat error handling mode
In order to replace certain /api/rest_v1 endpoints, we need to have something in MediaWiki that generates a compatible responser. The MediaWiki REST API error format does not match RESTbase. So the easiest approach seemed to be to add a compatibility mode, triggered using the x-restbase-compat header. This can be set via the gateway when rerouting the request. Bug: T374136 Change-Id: I73934940d367be52941bd27861c248ab5bcfb5d2
Diffstat (limited to 'includes/Rest/Module/Module.php')
-rw-r--r--includes/Rest/Module/Module.php8
1 files changed, 7 insertions, 1 deletions
diff --git a/includes/Rest/Module/Module.php b/includes/Rest/Module/Module.php
index dcfc01af4550..46d73b0b7e18 100644
--- a/includes/Rest/Module/Module.php
+++ b/includes/Rest/Module/Module.php
@@ -268,7 +268,13 @@ abstract class Module {
$response = $this->executeHandler( $handler );
} catch ( HttpException $e ) {
- $response = $this->responseFactory->createFromException( $e );
+ $extraData = [];
+ if ( $this->router->isRestbaseCompatEnabled( $request )
+ && $e instanceof LocalizedHttpException
+ ) {
+ $extraData = $this->router->getRestbaseCompatErrorData( $request, $e );
+ }
+ $response = $this->responseFactory->createFromException( $e, $extraData );
} catch ( Throwable $e ) {
// Note that $handler is allowed to be null here.
$this->errorReporter->reportError( $e, $handler, $request );