使用ajax调用自定义错误处理程序

时间:2016-02-06 07:21:28

标签: php ajax error-handling syntax-error

我已经在PHP中编写了我自己的自定义错误处理程序,但它的工作非常完美,但如果我在ajax文件中出现解析错误(例如文件中的错误处理程序错误),则错误处理程序不会出错。工作......所有其他错误都没问题:)

有人能帮助我吗?

 private function __construct(){
    set_error_handler(array($this, 'errorHandler'));
    set_exception_handler(array($this, 'exceptionHandler'));
    register_shutdown_function(array($this, 'fatalHandler'));
}
public function errorHandler($errorNo, $errorMsg, $errorFile, $errorLine){
    $this->errorNo = $errorNo;
    $this->errorMsg = $errorMsg;
    $this->errorFile = $errorFile;
    $this->errorLine = $errorLine;

    switch ($errorNo) {
        case E_NOTICE:
        case E_USER_NOTICE:
        case E_DEPRECATED:
        case E_USER_DEPRECATED:
        case E_STRICT:
        case E_WARNING:
        case E_COMPILE_WARNING:
        case E_RECOVERABLE_ERROR:
        case E_USER_WARNING:
            $error = $this->generateErrorMessage();
            error_log('Fehler #'.$this->errorNumbers[$errorNo]['ERRORCODE'].': '.$error);
            $this->sendErrorMail($error,$this->errorNumbers[$errorNo]['ERRORCODE']);
            break;

        case E_ERROR:
        case E_USER_ERROR:
        case E_PARSE:
        case E_COMPILE_ERROR:
            $error = $this->generateErrorMessage();
            error_log('Fehler #' . $this->errorNumbers[$errorNo]['ERRORCODE'] . ': ' . $error);
            $this->sendErrorMail($error, $this->errorNumbers[$errorNo]['ERRORCODE']);
            if(!isAjax()) {
                redirect('?show=error&errorCode=' . $this->errorNumbers[$errorNo]['ERRORCODE']);
            } else {
                ob_clean();
                echo buildFatalErrorResponse($this->errorNumbers[$errorNo]['ERRORCODE']);
                die();
            }
            break;

        default:
            $error = $this->generateErrorMessage();
            error_log('Fehler #'.$this->errorNumbers[$errorNo]['ERRORCODE'].': '.$error);
            $this->sendErrorMail($error,$this->errorNumbers[$errorNo]['ERRORCODE']);
            if(!isAjax()) {
                redirect('?show=error&errorCode=' . $this->errorNumbers[$errorNo]['ERRORCODE']);
            } else {
                ob_clean();
                echo buildFatalErrorResponse($this->errorNumbers[$errorNo]['ERRORCODE']);
                die();
            }
            break;
    }
    return true;
}

public function fatalHandler(){
    $error = error_get_last();
    if($error) {
        $this->errorHandler($error['type'],$error['message'],$error['file'],$error['line']);
    }
}

这里是ajax文件:

  

BO_ErrorHandler ::的getInstance();

     

如果(!isAjax()){       重定向(' /显示= NOTFOUND'?); }

     

fghkjlkl

0 个答案:

没有答案