diff options
author | bpirkle <bpirkle@wikimedia.org> | 2024-09-16 11:39:02 -0500 |
---|---|---|
committer | bpirkle <bpirkle@wikimedia.org> | 2024-09-16 18:09:12 -0500 |
commit | 90494183bba46518a496275c12cdd126d6065a58 (patch) | |
tree | 578faa529c43c1a073002bfd20853e0baba37a37 /includes/Rest/Module/Module.php | |
parent | d8efb20b3fdef7a6959f787b7da51a11feec2ff1 (diff) | |
download | mediawikicore-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.php | 8 |
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 ); |