X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiCSPReport.php;h=3a78c1350c89b11c3702457834c066e4194cb55a;hb=9f2b48a970645f3a0a6b319e5c131e2b0bd1b259;hp=5a0edfcd82ddc9cedecd82d0ee9f39bd3eee0c1b;hpb=dcdb8e463e3b2be121c61c91df13ea36d270a602;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiCSPReport.php b/includes/api/ApiCSPReport.php index 5a0edfcd82..3a78c1350c 100644 --- a/includes/api/ApiCSPReport.php +++ b/includes/api/ApiCSPReport.php @@ -137,8 +137,11 @@ class ApiCSPReport extends ApiBase { } $status = FormatJson::parse( $postBody, FormatJson::FORCE_ASSOC ); if ( !$status->isGood() ) { - list( $code, ) = $this->getErrorFromStatus( $status ); - $this->error( $code, __METHOD__ ); + $msg = $status->getErrors()[0]['message']; + if ( $msg instanceof Message ) { + $msg = $msg->getKey(); + } + $this->error( $msg, __METHOD__ ); } $report = $status->getValue(); @@ -176,15 +179,17 @@ class ApiCSPReport extends ApiBase { * * @param $code String error code * @param $method String method that made error - * @throws UsageException Always + * @throws ApiUsageException Always */ private function error( $code, $method ) { $this->log->info( 'Error reading CSP report: ' . $code, [ 'method' => $method, 'user-agent' => $this->getRequest()->getHeader( 'user-agent' ) ] ); - // 500 so it shows up in browser's developer console. - $this->dieUsage( "Error processing CSP report: $code", 'cspreport-' . $code, 500 ); + // Return 400 on error for user agents to display, e.g. to the console. + $this->dieWithError( + [ 'apierror-csp-report', wfEscapeWikiText( $code ) ], 'cspreport-' . $code, [], 400 + ); } public function getAllowedParams() {