Changeset 2404


Ignore:
Timestamp:
12/24/2011 4:51:20 AM (5 months ago)
Author:
lowjoel
Message:

Since we can read the output stream for data even when the Download call fails (due to a HTTP response code error), we should try that and output anything that arrives if we can so that errors are not so mysterious and causes can be traced.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/website/scripts/BuildPublish.php

    r2396 r2404  
    1717require_once('BuildBranch.php'); 
    1818require_once('BuildUtil.php'); 
     19 
     20/** 
     21 * Reads a HTTP response stream and strips it of HTML, returning as a buffer. 
     22 * This is similar to file_get_contents 
     23 *  
     24 * @param resource $file The file stream to read. 
     25 * @return string The contents of the response, without HTML. 
     26 * @throws Exception An I/O error occurred. 
     27 */ 
     28function http_get_contents($file) 
     29{ 
     30    $result = ''; 
     31    while (($line = fgetss($file, 4096)) !== false) 
     32        $result .= $line . "\n"; 
     33    if (!feof($file)) 
     34        throw new Exception('Unexpected fgets() failure'); 
     35 
     36    return $result; 
     37} 
    1938 
    2039$file = fopen($argv[3], 'rb'); 
     
    5170            $serverResponse, $build_username, $build_password); 
    5271        fseek($serverResponse, 0); 
    53         while (($line = fgetss($serverResponse, 4096)) !== false) 
    54             echo $line; 
    55         if (!feof($serverResponse)) 
    56             throw new Exception('Unexpected fgets() failure'); 
     72        echo http_get_contents($serverResponse); 
    5773        fclose($serverResponse); 
    5874    } 
    5975    catch (Exception $e) 
    6076    { 
     77        fseek($serverResponse, 0); 
     78        $serverResponseText = http_get_contents($serverResponse); 
    6179        fclose($serverResponse); 
     80         
     81        echo 'Error: ' . $e->getMessage(); 
     82        if (!empty($serverResponseText)) 
     83            echo " with error message:\n" . $serverResponseText . "\n"; 
     84         
    6285        Delete(SHELL_WEB_ROOT . $installerPath, $sftp_username, $sftp_password); 
    63         throw $e; 
     86        exit(1); 
    6487    } 
    6588} 
Note: See TracChangeset for help on using the changeset viewer.