Пример #1
0
 /**
  * Render an exception as the sole output.
  *
  * @param Exception $Ex The exception to render.
  */
 public function RenderException($Ex)
 {
     if ($this->DeliveryMethod() == DELIVERY_METHOD_XHTML) {
         try {
             switch ($Ex->getCode()) {
                 case 401:
                     Gdn::Dispatcher()->Dispatch('DefaultPermission');
                     break;
                 case 404:
                     Gdn::Dispatcher()->Dispatch('Default404');
                     break;
                 default:
                     Gdn_ExceptionHandler($Ex);
             }
         } catch (Exception $Ex2) {
             Gdn_ExceptionHandler($Ex);
         }
         return;
     }
     // Make sure the database connection is closed before exiting.
     $this->Finalize();
     $this->SendHeaders();
     $Code = $Ex->getCode();
     if (Debug()) {
         $Message = $Ex->getMessage() . "\n\n" . $Ex->getTraceAsString();
     } else {
         $Message = $Ex->getMessage();
     }
     if ($Code >= 100 && $Code <= 505) {
         header("HTTP/1.0 {$Code}", TRUE, $Code);
     } else {
         header('HTTP/1.0 500', TRUE, 500);
     }
     $Data = array('Code' => $Code, 'Exception' => $Message);
     switch ($this->DeliveryMethod()) {
         case DELIVERY_METHOD_JSON:
             header('Content-Type: application/json', TRUE);
             if ($Callback = $this->Request->GetValueFrom(Gdn_Request::INPUT_GET, 'callback', FALSE)) {
                 // This is a jsonp request.
                 exit($Callback . '(' . json_encode($Data) . ');');
             } else {
                 // This is a regular json request.
                 exit(json_encode($Data));
             }
             break;
             //         case DELIVERY_METHOD_XHTML:
             //            Gdn_ExceptionHandler($Ex);
             //            break;
         //         case DELIVERY_METHOD_XHTML:
         //            Gdn_ExceptionHandler($Ex);
         //            break;
         case DELIVERY_METHOD_XML:
             header('Content-Type: text/xml', TRUE);
             array_map('htmlspecialchars', $Data);
             exit("<Exception><Code>{$Data['Code']}</Code><Message>{$Data['Exception']}</Message></Exception>");
             break;
     }
 }
 /**
  * Render an exception as the sole output.
  *
  * @param Exception $Ex The exception to render.
  */
 public function RenderException($Ex)
 {
     if ($this->DeliveryMethod() == DELIVERY_METHOD_XHTML) {
         try {
             if (is_a($Ex, 'Gdn_UserException')) {
                 Gdn::Dispatcher()->PassData('Code', $Ex->getCode())->PassData('Exception', $Ex->getMessage())->PassData('Message', $Ex->getMessage())->PassData('Trace', $Ex->getTraceAsString())->PassData('Url', Url())->PassData('Breadcrumbs', $this->Data('Breadcrumbs', array()))->Dispatch('/home/error');
             } else {
                 switch ($Ex->getCode()) {
                     case 401:
                         Gdn::Dispatcher()->PassData('Message', $Ex->getMessage())->PassData('Url', Url())->Dispatch('DefaultPermission');
                         break;
                     case 404:
                         Gdn::Dispatcher()->PassData('Message', $Ex->getMessage())->PassData('Url', Url())->Dispatch('Default404');
                         break;
                     default:
                         Gdn_ExceptionHandler($Ex);
                 }
             }
         } catch (Exception $Ex2) {
             Gdn_ExceptionHandler($Ex);
         }
         return;
     }
     // Make sure the database connection is closed before exiting.
     $this->Finalize();
     $this->SendHeaders();
     $Code = $Ex->getCode();
     $Data = array('Code' => $Code, 'Exception' => $Ex->getMessage(), 'Class' => get_class($Ex));
     if (Debug()) {
         if ($Trace = Trace()) {
             // Clear passwords from the trace.
             array_walk_recursive($Trace, function (&$Value, $Key) {
                 if (in_array(strtolower($Key), array('password'))) {
                     $Value = '***';
                 }
             });
             $Data['Trace'] = $Trace;
         }
         if (!is_a($Ex, 'Gdn_UserException')) {
             $Data['StackTrace'] = $Ex->getTraceAsString();
         }
         $Data['Data'] = $this->Data;
     }
     // Try cleaning out any notices or errors.
     @ob_clean();
     if ($Code >= 400 && $Code <= 505) {
         safeHeader("HTTP/1.0 {$Code}", TRUE, $Code);
     } else {
         safeHeader('HTTP/1.0 500', TRUE, 500);
     }
     switch ($this->DeliveryMethod()) {
         case DELIVERY_METHOD_JSON:
             if (($Callback = $this->Request->GetValueFrom(Gdn_Request::INPUT_GET, 'callback', FALSE)) && $this->AllowJSONP()) {
                 safeHeader('Content-Type: application/javascript', TRUE);
                 // This is a jsonp request.
                 exit($Callback . '(' . json_encode($Data) . ');');
             } else {
                 safeHeader('Content-Type: application/json', TRUE);
                 // This is a regular json request.
                 exit(json_encode($Data));
             }
             break;
             //         case DELIVERY_METHOD_XHTML:
             //            Gdn_ExceptionHandler($Ex);
             //            break;
         //         case DELIVERY_METHOD_XHTML:
         //            Gdn_ExceptionHandler($Ex);
         //            break;
         case DELIVERY_METHOD_XML:
             safeHeader('Content-Type: text/xml', TRUE);
             array_map('htmlspecialchars', $Data);
             exit("<Exception><Code>{$Data['Code']}</Code><Class>{$Data['Class']}</Class><Message>{$Data['Exception']}</Message></Exception>");
             break;
         default:
             safeHeader('Content-Type: text/plain', TRUE);
             exit($Ex->getMessage());
     }
 }