~jstys-z/helioviewer.org/webApp

« back to all changes in this revision

Viewing changes to api/src/Helper/ErrorHandler.php

  • Committer: Jeff Stys
  • Date: 2014-03-27 14:58:12 UTC
  • Revision ID: jstys@sesda3.com-20140327145812-w6zfy2rd8nrexvm6
Overhaul of API Documentation, Sidebar Toggle, Movie Player Dialog updates, Bug Fixes.

Overhaul of API documentation:
+  API documentation now lives at its own URL:  api/docs/v1/
+  API documentation has been separated from the API execution code to prevent documentation changes from interrupting live API requests.
+  API descriptions have been movied to verion-specific XML file(s), freeing it from the shackles of HTML and CSS markup.
+  Invalid API requests now display the documentation for the requested API action on the error page.

Hiding of News/Video sidebar
+ Added an icon button to the bottom of the Viewport to toggle the right-hand sidebar.
+ Modified the behavior of the fullscreen toggle to be compatible with the show/hide sidebar feature.
+ Added a keyboard shortcut, 's' to toggle the sidebar.

Miscellaneous Changes:
+  HV_API_URL is now used to prevent occassionaly problematic relative URLs.
+  For compatability reasons, an unexpected API parameter no longer results in an Exception.  Instead, such parameters are explicitely unset.
+  Minor cosmetic changes to the movie player dialog.
+  Replaced AddThis with standard Twitter and Facebook buttons.
+  Added footer link to Helioviewer twitter account.

Bug Fixes:
+  Fixed a bug with the database query in getMovieInformation() that was preventing the LEFT JOIN from properly returning a result when the joined table (movieFormats) did not have any associated rows.  A problem with the WHERE clause was eliminating the benefits of the LEFT JOIN.
+  Fixed a variable name typo associated with the mount wilson class event labels of NOAA SWPC Observer active regions.
+  Fixed a bug that was causing embedded Wordpress widgets to make an external API request to the HEK HER API when it wasn't necessary.

Apache Configuration Changes:
+  Need to add mod_rewrite rule to support version-specific API URIs (in use now by the API documentation).
      RewriteRule ^/api/(v[0-9\.]+)/([0-9a-zA-Z]*)/  /api/index.php?action=$2  [QSA,L]

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<?php
2
2
/**
3
3
 * Handles errors encountered during request processing.
4
 
 * 
 
4
 *
5
5
 * @param string $msg       The error message to display
6
6
 * @param int    $errorCode Error code number
7
 
 * 
 
7
 *
8
8
 * Error Codes:
9
9
 *    1 DATABASE    Unable to connect
10
10
 *    2 DATABASE    Query error
40
40
 *   61 JHV         JPX creation taking too long
41
41
 *   62 JHV         JPX summary file not found
42
42
 *  255 GENERAL     Unexpected error
43
 
 * 
44
 
 * 
45
 
 * Note: If multiple levels of verbosity are needed, one option would be to 
46
 
 *       split up the complete error message into it's separate parts, add 
47
 
 *       a "details" field with the full message, and display only the 
48
 
 *       top-level error message in "error" 
49
 
 * 
 
43
 *
 
44
 *
 
45
 * Note: If multiple levels of verbosity are needed, one option would be to
 
46
 *       split up the complete error message into it's separate parts, add
 
47
 *       a "details" field with the full message, and display only the
 
48
 *       top-level error message in "error"
 
49
 *
50
50
 * @see http://www.firephp.org/
51
51
 */
52
 
function handleError($msg, $errorCode=255)
53
 
{
54
 
    //error_log('Error Code '.$errorCode.': '.$msg);
 
52
function handleError($msg, $errorCode=255) {
 
53
 
 
54
    // error_log('Error Code '.$errorCode.': '.$msg);
55
55
    header('Content-type: application/json;charset=UTF-8');
56
 
    
 
56
 
57
57
    // JSON
58
58
    echo json_encode(array(
59
 
        "error" =>$msg,
60
 
        "errno" =>$errorCode
 
59
        'error' => $msg,
 
60
        'errno' => $errorCode
61
61
    ));
62
62
 
63
63
    // Fire PHP
64
 
    include_once HV_API_ROOT_DIR ."/lib/FirePHPCore/fb.php";
 
64
    include_once HV_API_DIR.'/lib/FirePHPCore/fb.php';
65
65
    FB::error($msg);
66
 
    
 
66
 
67
67
    // Don't log non-harmful errors
68
68
    $dontLog = array(12, 16, 23, 25, 26, 40, 44, 46);
69
69
 
70
 
    if (!in_array($errorCode, $dontLog)) {
 
70
    if ( !in_array($errorCode, $dontLog) ) {
71
71
        logErrorMsg($msg);
72
72
    }
73
73
}
74
74
 
75
75
/**
76
76
 * Logs an error message to the log whose location is specified in Config.ini
77
 
 * 
 
77
 *
78
78
 * @param string $error The body of the error message to be logged.
79
 
 * 
80
 
 * @return void 
 
79
 *
 
80
 * @return void
81
81
 */
82
 
function logErrorMsg($error, $prefix="")
83
 
{
 
82
function logErrorMsg($error, $prefix='') {
84
83
    // API request errors
85
 
    if (isset($_SERVER['HTTP_HOST']) && isset($_SERVER['REQUEST_URI'])) {
 
84
    if ( isset($_SERVER['HTTP_HOST']) && isset($_SERVER['REQUEST_URI']) ) {
86
85
        $source = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
87
 
    } else {
 
86
    }
 
87
    else {
88
88
        // Resque worker errors
89
 
        $source = "Resque: " . $_SERVER['QUEUE'];
 
89
        $source = 'Resque: ' . $_SERVER['QUEUE'];
90
90
    }
91
 
    
92
 
    $log = HV_LOG_DIR . "/$prefix" . date("Ymd_His") . ".log";
93
 
    
94
 
    $template = "====[DATE]====================\n\n%s\n\n====[SOURCE]===================\n\n%s\n\n"
 
91
 
 
92
    $log = HV_LOG_DIR.'/'.$prefix.date('Ymd_His').'.log';
 
93
 
 
94
    $template = "====[DATE]====================\n\n%s\n\n"
 
95
              . "====[SOURCE]==================\n\n%s\n\n"
95
96
              . "====[MESSAGE]=================\n\n%s";
96
 
    
97
 
    $msg = sprintf($template, date("Y/m/d H:i:s"), $source, $error);
98
 
    
99
 
    if (!empty($_REQUEST)) {
 
97
 
 
98
    $msg = sprintf($template, date('Y/m/d H:i:s'), $source, $error);
 
99
 
 
100
    if ( !empty($_REQUEST) ) {
100
101
        $msg .= "\n\n====[POST]=================\n\n";
101
102
        foreach ($_REQUEST as $key => $value) {
102
103
           $msg .= "'$key' => $value\n";