Codes set on other Exception types are unlikely to be intended as HTTP
codes.
Bug: T228758
Change-Id: Ia6a53cb621f87ff97d5f16215a1b09ae11ca8f53
// Printer may not be initialized if the extractRequestParams() fails for the main module
$this->createErrorPrinter();
// 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;
+
- $this->printResult( $e->getCode() );
+ $this->printResult( $httpCode );
} catch ( ApiUsageException $ex ) {
// The error printer itself is failing. Try suppressing its request
// parameters and redo.
} catch ( ApiUsageException $ex ) {
// The error printer itself is failing. Try suppressing its request
// parameters and redo.
$this->mPrinter = null;
$this->createErrorPrinter();
$this->mPrinter->forceDefaultParams();
$this->mPrinter = null;
$this->createErrorPrinter();
$this->mPrinter->forceDefaultParams();
$response->statusHeader( 200 ); // Reset in case the fallback doesn't want a non-200
}
$response->statusHeader( 200 ); // Reset in case the fallback doesn't want a non-200
}
- $this->printResult( $e->getCode() );
+ $this->printResult( $httpCode );