X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiMain.php;h=8389b24c9c57fed70a68365c49c807047e3e03b6;hb=acb2e15615a5cc792b08dd62494dd0608b1a9d33;hp=a77136de1b220a248aafe527b9cc9c04507dda2f;hpb=67d01c452da591faced0a4be7940acf4f3292928;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index a77136de1b..8389b24c9c 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -593,9 +593,13 @@ class ApiMain extends ApiBase { // Printer may not be initialized if the extractRequestParams() fails for the main module $this->createErrorPrinter(); + // Get desired HTTP code from an ApiUsageException. Don't use codes from other + // exception types, as they are unlikely to be intended as an HTTP code. + $httpCode = $e instanceof ApiUsageException ? $e->getCode() : 0; + $failed = false; try { - $this->printResult( $e->getCode() ); + $this->printResult( $httpCode ); } catch ( ApiUsageException $ex ) { // The error printer itself is failing. Try suppressing its request // parameters and redo. @@ -617,10 +621,10 @@ class ApiMain extends ApiBase { $this->mPrinter = null; $this->createErrorPrinter(); $this->mPrinter->forceDefaultParams(); - if ( $e->getCode() ) { + if ( $httpCode ) { $response->statusHeader( 200 ); // Reset in case the fallback doesn't want a non-200 } - $this->printResult( $e->getCode() ); + $this->printResult( $httpCode ); } }