diff options
author | Dreamy Jazz <wpgbrown@wikimedia.org> | 2024-04-23 13:28:29 +0100 |
---|---|---|
committer | Dreamy Jazz <wpgbrown@wikimedia.org> | 2024-04-23 21:15:23 +0100 |
commit | d6ac3dac743e681423ff39996aeb03130bc3d53e (patch) | |
tree | 1f86f15240c2a8a87b0a90b5a9972e415c3d4c37 /includes/api/ApiMain.php | |
parent | 75b00571a6e659d98b0df265b304bb953105292f (diff) | |
download | mediawikicore-d6ac3dac743e681423ff39996aeb03130bc3d53e.tar.gz mediawikicore-d6ac3dac743e681423ff39996aeb03130bc3d53e.zip |
Catch exceptions from ::isWriteMode in ApiMain::sendCacheHeaders
Why:
* Modules that extend ApiQueryBase are loaded using the ApiQuery
module. This defines an override to the ApiBase::isWriteMode
method that loads the modules.
* Using the mModule when $isError is true could lead to the
exception that was thrown in ::executeAction being thrown again.
* Therefore, ApiMain::sendCacheHeaders should only call the
ApiBase::isWriteMode method if the request did not fail
with an error that caused $isError to be true.
* Without this fix, ApiUsageExceptions appear in logstash as
exceptions, as described in T363133.
What:
* Only interact with $this->mModule if the $isError argument
is false. If $isError is true, assume that ::isWriteMode
would return true. Assuming this will also avoid error
responses being marked as fresh for any amount of time, as
the error may be temporary.
* Add a test that verifies that the method does not throw if
ApiBase::isWriteMode throws an ApiUsageException.
Bug: T363133
Change-Id: I41d869c257878b8a94d6c40332e2028405de8729
Diffstat (limited to 'includes/api/ApiMain.php')
-rw-r--r-- | includes/api/ApiMain.php | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index 7d38d740801f..4773d9b7d2a1 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -1243,7 +1243,7 @@ class ApiMain extends ApiBase { $maxage = 0; if ( isset( $this->mCacheControl['max-age'] ) ) { $maxage = $this->mCacheControl['max-age']; - } elseif ( ( $this->mModule && !$this->mModule->isWriteMode() ) || + } elseif ( ( !$isError && $this->mModule && !$this->mModule->isWriteMode() ) || $this->mCacheMode !== 'private' ) { $maxage = $this->getParameter( 'maxage' ); |