Reduced some instances of HTTP 500 in thumb.php
authorAaron Schulz <aschulz@wikimedia.org>
Wed, 26 Aug 2015 18:52:23 +0000 (11:52 -0700)
committerBryanDavis <bdavis@wikimedia.org>
Wed, 26 Aug 2015 19:56:26 +0000 (19:56 +0000)
* This add noise to logs and graphs that can look like outages
  due to a single crawler.

Bug: T110109
Change-Id: Ie2a1edd0330b0f858729fcc56c828c11d9c7476c

thumb.php

index 25bca87..eea6dda 100644 (file)
--- a/thumb.php
+++ b/thumb.php
@@ -221,7 +221,7 @@ function wfStreamThumb( array $params ) {
                wfThumbErrorText( 404, "The source file '$fileName' does not exist." );
                return;
        } elseif ( $img->getPath() === false ) {
-               wfThumbErrorText( 500, "The source file '$fileName' is not locally accessible." );
+               wfThumbErrorText( 400, "The source file '$fileName' is not locally accessible." );
                return;
        }
 
@@ -316,10 +316,10 @@ function wfStreamThumb( array $params ) {
 
        $user = RequestContext::getMain()->getUser();
        if ( !wfThumbIsStandard( $img, $params ) && $user->pingLimiter( 'renderfile-nonstandard' ) ) {
-               wfThumbError( 500, wfMessage( 'actionthrottledtext' )->parse() );
+               wfThumbError( 429, wfMessage( 'actionthrottledtext' )->parse() );
                return;
        } elseif ( $user->pingLimiter( 'renderfile' ) ) {
-               wfThumbError( 500, wfMessage( 'actionthrottledtext' )->parse() );
+               wfThumbError( 429, wfMessage( 'actionthrottledtext' )->parse() );
                return;
        }
 
@@ -555,7 +555,7 @@ function wfExtractThumbParams( $file, $params ) {
  * @return void
  */
 function wfThumbErrorText( $status, $msgText ) {
-       return wfThumbError( $status, htmlspecialchars( $msgText ) );
+       wfThumbError( $status, htmlspecialchars( $msgText ) );
 }
 
 /**
@@ -570,10 +570,8 @@ function wfThumbError( $status, $msgHtml ) {
 
        header( 'Cache-Control: no-cache' );
        header( 'Content-Type: text/html; charset=utf-8' );
-       if ( $status == 400 ) {
-               HttpStatus::header( 400 );
-       } elseif ( $status == 404 ) {
-               HttpStatus::header( 404 );
+       if ( $status == 400 || $status == 404 || $status == 429 ) {
+               HttpStatus::header( $status );
        } elseif ( $status == 403 ) {
                HttpStatus::header( 403 );
                header( 'Vary: Cookie' );