/** * @return int|null */ public function getErrorCode() { if ($this->error instanceof Error) { return $this->error->getCode(); } return null; }
public function testGetAttributes() { $this->assertEquals('error_type', $this->error->getType()); $this->assertEquals('error_file', $this->error->getFile()); $this->assertEquals('error_line', $this->error->getLine()); $this->assertEquals('error_char', $this->error->getChar()); $this->assertEquals('error_code', $this->error->getCode()); }
/** * Wraps the passed Error class * * @param Error $error the Error object */ public function __construct($error) { $this->_error = $error; $message = $error->getMessage(); $code = $error->getCode(); parent::__construct(sprintf('(%s) - %s', get_class($error), $message), $code); }
public function testBasic() { $error = new Error('error', 1); $this->assertSame('error', (string) $error); $this->assertSame('error', $error->getMessage()); $this->assertSame(1, $error->getCode()); }
/** * Set error response * @param \Sonic\Controller\Error|integer|string $message Error message object, error code or message string * @param integer $code Error code, only used if message is a string * @param integer $httpCode HTTP status code * @return FALSE */ protected function error($message = 'invalid request', $code = 0, $httpCode = 0) { if (is_numeric($message)) { $error = new Error($message); $code = $error->getCode(); $message = $error->getMessage(); } else { if ($message instanceof Error) { $code = $message->getCode(); $message = $message->getMessage(); } } $this->view->response = array('success' => 0, 'error_code' => $code, 'error_description' => $message); if ($httpCode) { $this->httpStatus($httpCode); } return FALSE; }
/** * @param Exception | Error $e */ function handleException($e) { $request = \OC::$server->getRequest(); // in case the request content type is text/xml - we assume it's a WebDAV request $isXmlContentType = strpos($request->getHeader('Content-Type'), 'text/xml'); if ($isXmlContentType === 0) { // fire up a simple server to properly process the exception $server = new Server(); if (!$e instanceof RemoteException) { // we shall not log on RemoteException $server->addPlugin(new ExceptionLoggerPlugin('webdav', \OC::$server->getLogger())); } $server->on('beforeMethod', function () use($e) { if ($e instanceof RemoteException) { switch ($e->getCode()) { case OC_Response::STATUS_SERVICE_UNAVAILABLE: throw new ServiceUnavailable($e->getMessage()); case OC_Response::STATUS_NOT_FOUND: throw new \Sabre\DAV\Exception\NotFound($e->getMessage()); } } $class = get_class($e); $msg = $e->getMessage(); throw new ServiceUnavailable("{$class}: {$msg}"); }); $server->exec(); } else { $statusCode = OC_Response::STATUS_INTERNAL_SERVER_ERROR; if ($e instanceof \OC\ServiceUnavailableException) { $statusCode = OC_Response::STATUS_SERVICE_UNAVAILABLE; } if ($e instanceof RemoteException) { // we shall not log on RemoteException OC_Response::setStatus($e->getCode()); OC_Template::printErrorPage($e->getMessage()); } else { \OC::$server->getLogger()->logException($e, ['app' => 'remote']); OC_Response::setStatus($statusCode); OC_Template::printExceptionErrorPage($e); } } }
/** * Main function for uploading data */ public function uploadData() { $request = \Bitrix\Main\Context::getCurrent()->getRequest(); $post = array_merge($request->getQueryList()->toArray(), $request->getPostList()->toArray()); $error = ""; $post = self::__UnEscape($post); $status = null; if ($this->getPost("type") != "brief") { $eventName = $this->log->getValue("executed") == false ? "onUploadIsStarted" : "onUploadIsContinued"; $this->log->setValue("executed", true); $logData = $this->log->getValues(); $packData = $this->packLog->getValues(); foreach (GetModuleEvents(self::EVENT_NAME, $eventName, true) as $arEvent) { if (ExecuteModuleEventEx($arEvent, array(&$packData, &$logData, &$post, &$_FILES, &$error)) === false) { $status = new Error("BXU350.1", $error); break; } } if ($status === null) { $eventName = $this->packLog->getValue("executed") == false ? "onPackageIsContinued" : "onPackageIsStarted"; $this->packLog->setValue("executed", true); foreach (GetModuleEvents(self::EVENT_NAME, $eventName, true) as $arEvent) { if (ExecuteModuleEventEx($arEvent, array(&$packData, &$logData, &$post, &$_FILES, &$error)) === false) { $status = new Error("BXU350.1", $error); break; } } } $this->log->setValues($logData); $this->packLog->setValues($packData); } if ($status === null) { $data = array(); if (!empty($post[self::FILE_NAME])) { foreach ($post[self::FILE_NAME] as $fileID => $props) { $hash = $this->getHash(array("id" => $fileID, "name" => $props["name"])); $data[$fileID] = array_merge($props, array("status" => "inprogress", "hash" => $hash, "id" => $fileID, "files" => array())); if (FileInputUtility::instance()->checkFile($this->CID, $hash)) { $data[$fileID] = self::merge($data[$fileID], $this->getFromCache($data[$fileID]["hash"])); if ($props["restored"] == "Y") { $data[$fileID]["status"] = "inprogress"; } } } } /*@var $files array*/ $files = $this->getUploadedFiles($data); $logData = $this->log->getValues(); $packData = $this->packLog->getValues(); foreach ($data as $fileID => $file) { if (!$this->checkTime()) { break; } $result = new Status($file["status"]); if ($result->getStatus() == "inprogress") { unset($file["restored"]); unset($file["executed"]); if (array_key_exists($fileID, $files)) { FileInputUtility::instance()->registerFile($this->CID, $file["hash"]); foreach ($files[$fileID] as $f) { $res = $this->checkFile($f, $file); if ($res instanceof Error) { $result = $res; break; } } } if ($result->getStatus() == "inprogress") { $result = $this->saveFile($file); } } if (array_key_exists("restored", $file) && array_key_exists("executed", $file) && array_key_exists("~status", $file)) { unset($file["restored"]); unset($file["executed"]); $result = new Status($file["~status"]); } $file["~status"] = $result->getStatus(); if ($result->getStatus() == "uploaded" && $this->getPost("type") != "brief" && !array_key_exists("executed", $file)) { $packData1 = $packData; $logData1 = $logData; $file["executed"] = "Y"; foreach (GetModuleEvents(self::EVENT_NAME, "onFileIsUploaded", true) as $arEvent) { $error = ""; if (!ExecuteModuleEventEx($arEvent, array($file["hash"], &$file, &$packData, &$logData, &$error))) { $result = new Error("BXU350.1", $error); $file["executed"] = "error"; break; } } if ($logData1 != $logData) { $this->log->setValues($logData); } if ($packData1 != $packData) { $this->packLog->setValues($packData); } } $file["status"] = $result->getStatus(); $this->setIntoCache($file["hash"], $file); // it is a compatibility $log = array("status" => $file["status"], "hash" => $file["hash"]); if ($result instanceof Error) { $log += array("error" => $result->getMessage(), "errorCode" => $result->getCode()); if (empty($log["error"])) { $log["error"] = "Unknown error."; } // trigger_error("Uploading error: ".$file["name"]." wasn't uploaded: ".$log["error"]." [".$log["errorCode"]."]", E_USER_WARNING); } $this->files[$fileID] = $log + array("file" => $file); if ($file["status"] == "uploaded" || $file["status"] == "error") { $this->packLog->setValue("files", array($file["id"] => $file["status"])); } } $declaredFiles = (int) $this->packLog->getValue("filesCount"); if ($declaredFiles > 0 && $declaredFiles == count($this->packLog->getValue("files"))) { $status = new Status("done"); if ($this->getPost("type") !== "brief") { foreach (GetModuleEvents(self::EVENT_NAME, "onPackageIsFinished", true) as $arEvent) { if (ExecuteModuleEventEx($arEvent, array($packData, $logData, $post, $this->files)) === false) { $status = new Error("BXU350.1", $error); break; } } } } else { $status = new Status("inprogress"); } if ($this->getPost("type") == "brief" || $status->getStatus() == "inprogress") { $this->log->setValues($logData); $this->packLog->setValues($packData); } else { $this->packLog->unlink(); } } $this->status = $status->getStatus(); return $status; }
public function testGetCode() { $this->assertEquals(101, $this->error->getCode()); }
/** * Message as two immutable members code and message that can only be * set in the constructor * * @return null */ public function testGetCodeMessageSql() { $this->assertEquals($this->errCode, $this->error->getCode()); $this->assertEquals($this->errText, $this->error->getMessage()); $this->assertEquals($this->sqlState, $this->error->getSqlState()); }
public function testGetCode() { $error = new Error(42, 'Unknown error'); $this->assertEquals(42, $error->getCode()); }
public function testGetters() { $error = new Error(123, 'foo'); $this->assertEquals(123, $error->getCode()); $this->assertEquals('foo', $error->getMessage()); }
/** * Handles a unexpected error in production mode. * * @param \Es\System\SystemEvent $systemEvent The system event * @param \Exception|\Error $exception The exception or the error */ public function handleProductionError(SystemEvent $systemEvent, $exception) { $details = ['details' => 'The resource is temporary unavailable']; $result = json_encode($details); $body = Stream::make($result); $status = 503; if ($exception instanceof ExceptionInterface && $exception->getCode()) { $status = $exception->getCode(); } $response = new Response($status, $body, ['Content-Type' => 'application/problem+json']); $this->processResponse($response, $systemEvent); }
/** * Handles a unexpected error in production mode. * * @param \Es\System\SystemEvent $systemEvent The system event * @param \Exception|\Error $exception The exception or the error */ public function handleProductionError(SystemEvent $systemEvent, $exception) { $renderer = $this->getRenderer(); $result = $renderer->render('error/production'); $body = Stream::make($result); $status = 503; if ($exception instanceof ExceptionInterface && $exception->getCode()) { $status = $exception->getCode(); } $response = new Response($status, $body, ['Content-Type' => 'text/html']); $this->processResponse($response, $systemEvent); }
/** * New exception. * * @param Exception $exception * @param boolean $printError * show error or not * @param boolean $clear * clear the errorlog * @param string $errorFile * file to save to */ public static function newMessage(\Error $exception) { $message = $exception->getMessage(); $code = $exception->getCode(); $file = $exception->getFile(); $line = $exception->getLine(); $trace = $exception->getTraceAsString(); $trace = str_replace(DB_PASS, '********', $trace); $date = date('M d, Y G:iA'); $logMessage = "<h3>Exception information:</h3>\n\n <p><strong>Date:</strong> {$date}</p>\n\n <p><strong>Message:</strong> {$message}</p>\n\n <p><strong>Code:</strong> {$code}</p>\n\n <p><strong>File:</strong> {$file}</p>\n\n <p><strong>Line:</strong> {$line}</p>\n\n <h3>Stack trace:</h3>\n\n <pre>{$trace}</pre>\n\n <hr />\n"; $errorFile = self::getCurrentErrorLog(); if (is_file($errorFile) === false) { file_put_contents($errorFile, ''); } if (self::$clear) { $f = fopen($errorFile, "r+"); if ($f !== false) { ftruncate($f, 0); fclose($f); } $content = null; } else { $content = file_get_contents($errorFile); } file_put_contents($errorFile, $logMessage . $content); if (self::$printError == true) { echo $logMessage; exit; } }
protected function FormatErrorMessage(Error $Error) { return $Error->getTimestamp() . ' [' . $Error->getCode() . '] "' . $Error->getMessage() . '" in file: ' . $Error->getFilepath() . ', line: ' . $Error->getLine() . PHP_EOL . $Error->getRequest(); }