improve logging
This commit is contained in:
parent
7bbe4f8a51
commit
e677f619f0
|
@ -34,6 +34,10 @@ class Helper {
|
|||
return $this->userSession->getUser()->getUID();
|
||||
}
|
||||
|
||||
public function logException(\Throwable $e) : void {
|
||||
$this->logger->logException($e, ['app' => $this->appName]);
|
||||
}
|
||||
|
||||
public function handleErrorResponse(callable $respond) : JSONResponse {
|
||||
try {
|
||||
// retry on LockedException
|
||||
|
@ -51,16 +55,16 @@ class Helper {
|
|||
}
|
||||
$response = $data instanceof JSONResponse ? $data : new JSONResponse($data);
|
||||
} catch (NoteDoesNotExistException $e) {
|
||||
$this->logger->logException($e, [ 'app' => $this->appName ]);
|
||||
$this->logException($e);
|
||||
$response = new JSONResponse([], Http::STATUS_NOT_FOUND);
|
||||
} catch (InsufficientStorageException $e) {
|
||||
$this->logger->logException($e, [ 'app' => $this->appName ]);
|
||||
$this->logException($e);
|
||||
$response = new JSONResponse([], Http::STATUS_INSUFFICIENT_STORAGE);
|
||||
} catch (\OCP\Lock\LockedException $e) {
|
||||
$this->logger->logException($e, [ 'app' => $this->appName ]);
|
||||
$this->logException($e);
|
||||
$response = new JSONResponse([], Http::STATUS_LOCKED);
|
||||
} catch (\Throwable $e) {
|
||||
$this->logger->logException($e, [ 'app' => $this->appName ]);
|
||||
$this->logException($e);
|
||||
$response = new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
$response->addHeader('X-Notes-API-Versions', implode(', ', Application::$API_VERSIONS));
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace OCA\Notes\Controller;
|
|||
use OCA\Notes\Service\NotesService;
|
||||
use OCA\Notes\Service\MetaService;
|
||||
use OCA\Notes\Service\SettingsService;
|
||||
use OCA\Notes\Service\NoteDoesNotExistException;
|
||||
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\IRequest;
|
||||
|
@ -82,13 +83,17 @@ class NotesController extends Controller {
|
|||
// check if note exists
|
||||
try {
|
||||
$this->notesService->get($userId, $lastViewedNote);
|
||||
} catch (\Exception $ex) {
|
||||
} catch (\Throwable $ex) {
|
||||
if (!($ex instanceof NoteDoesNotExistException)) {
|
||||
$this->helper->logException($ex);
|
||||
}
|
||||
$this->settings->deleteUserValue($userId, $this->appName, 'notesLastViewedNote');
|
||||
$lastViewedNote = 0;
|
||||
$errorMessage = $this->l10n->t('The last viewed note cannot be accessed. ').$ex->getMessage();
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Throwable $e) {
|
||||
$this->helper->logException($e);
|
||||
$errorMessage = $this->l10n->t('The notes folder is not accessible: %s', $e->getMessage());
|
||||
}
|
||||
|
||||
|
|
|
@ -77,6 +77,7 @@ class Note {
|
|||
try {
|
||||
$data['content'] = $this->getContent();
|
||||
} catch (\Throwable $e) {
|
||||
$this->noteUtil->logException($e);
|
||||
$message = $this->noteUtil->getL10N()->t('Error').': ('.$this->file->getName().') '.$e->getMessage();
|
||||
$data['content'] = $message;
|
||||
$data['error'] = true;
|
||||
|
|
|
@ -50,6 +50,10 @@ class NoteUtil {
|
|||
return $this->logger;
|
||||
}
|
||||
|
||||
public function logException(\Throwable $e) : void {
|
||||
$this->logger->logException($e, ['app' => $this->appName]);
|
||||
}
|
||||
|
||||
public function getCategoryFolder(Folder $notesFolder, string $category) {
|
||||
$path = $notesFolder->getPath();
|
||||
// sanitise path
|
||||
|
|
|
@ -110,11 +110,7 @@ class NotesService {
|
|||
private function getNotesFolder(string $userId) : Folder {
|
||||
$userPath = $this->noteUtil->getRoot()->getUserFolder($userId)->getPath();
|
||||
$path = $userPath . '/' . $this->settings->get($userId, 'notesPath');
|
||||
try {
|
||||
$folder = $this->noteUtil->getOrCreateFolder($path);
|
||||
} catch (\Exception $e) {
|
||||
throw new NotesFolderException($path);
|
||||
}
|
||||
$folder = $this->noteUtil->getOrCreateFolder($path);
|
||||
return $folder;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue