Esempio n. 1
0
 /**
  * Handle an error.
  *
  * @param       int             $errorStatus    Error status code
  * @param       string          $errorMsg       Error message
  * @param       string          $errorFile      Error script file
  * @param       int             $errorLine      Error script line
  * @throws      ApiException                    API exception
  */
 public static function handle($errorStatus, $errorMsg, $errorFile, $errorLine)
 {
     // Build the complete error message
     $mailMsg = '<b>--- Spotzi ErrorHandler ---</b>' . PHP_EOL . PHP_EOL;
     $mailMsg .= 'Date: ' . Date::format() . PHP_EOL;
     $mailMsg .= 'Error status: ' . $errorStatus . PHP_EOL;
     $mailMsg .= 'Error message: ' . $errorMsg . PHP_EOL;
     $mailMsg .= 'Script name: ' . $errorFile . PHP_EOL;
     $mailMsg .= 'Line number: ' . $errorLine . PHP_EOL;
     //$mailMsg .= 'Request referer: ' . REQUEST_REFERER . PHP_EOL;
     //$mailMsg .= 'Request URL: ' . URL_BASE . ltrim(REQUEST_URI, '/') . PHP_EOL;
     if (isset($_SERVER['HTTP_USER_AGENT'])) {
         $mailMsg .= 'User agent: ' . $_SERVER['HTTP_USER_AGENT'];
     }
     // Determine whether debug mode is active
     if (debugMode()) {
         // In case debug mode is active, set the error message as the frontend message
         debugPrint($mailMsg);
     } else {
         // Send the error email when needed
         if (HttpStatus::emailStatus($errorStatus)) {
             // Prepare the error mailer
             Mail::addMailer(EMAIL_HOST, EMAIL_PORT, EMAIL_ERROR_FROM, EMAIL_ERROR_FROM_PASSWORD, BRAND_PRODUCT);
             // Send the error email
             Mail::send(EMAIL_ERROR_RECIPIENT, EMAIL_ERROR_FROM, EMAIL_ERROR_SUBJECT, nl2br($mailMsg));
         }
         throw new ApiException($errorStatus, $errorMsg);
     }
 }