diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2018-02-02 19:58:44 +0300 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2018-02-12 13:01:08 +0300 |
commit | 6012a5675e47dfe246496b6e5dd897492b11d3ad (patch) | |
tree | be4a39f31a9caf9b74f52ca5eef5f04a1fab4859 /lib/Controller/MessagesController.php | |
parent | ee4bb5471dfd6c5fe61b64793f26b3af05f06f00 (diff) |
Add API error wrapper middleware to API routes
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/Controller/MessagesController.php')
-rwxr-xr-x | lib/Controller/MessagesController.php | 37 |
1 files changed, 15 insertions, 22 deletions
diff --git a/lib/Controller/MessagesController.php b/lib/Controller/MessagesController.php index 3a18f5c86..b3f5f1cb7 100755 --- a/lib/Controller/MessagesController.php +++ b/lib/Controller/MessagesController.php @@ -30,7 +30,6 @@ namespace OCA\Mail\Controller; use OCA\Mail\Account; use OCA\Mail\Contracts\IMailManager; -use OCA\Mail\Exception\ServiceException; use OCA\Mail\Http\AttachmentDownloadResponse; use OCA\Mail\Http\HtmlResponse; use OCA\Mail\Model\IMAPMessage; @@ -39,7 +38,6 @@ use OCA\Mail\Service\IMailBox; use OCA\Mail\Service\Logger; use OCP\AppFramework\Controller; use OCP\AppFramework\Db\DoesNotExistException; -use OCP\AppFramework\Http; use OCP\AppFramework\Http\ContentSecurityPolicy; use OCP\AppFramework\Http\JSONResponse; use OCP\AppFramework\Http\TemplateResponse; @@ -112,6 +110,7 @@ class MessagesController extends Controller { /** * @NoAdminRequired + * @TrapError * * @param int $accountId * @param string $folderId @@ -164,6 +163,7 @@ class MessagesController extends Controller { /** * @NoAdminRequired + * @TrapError * * @param int $accountId * @param string $folderId @@ -171,16 +171,12 @@ class MessagesController extends Controller { * @return JSONResponse */ public function show($accountId, $folderId, $id) { - try { - $json = $this->loadMessage($accountId, $folderId, $id); - } catch (DoesNotExistException $ex) { - return new JSONResponse([], 404); - } - return new JSONResponse($json); + return new JSONResponse($this->loadMessage($accountId, $folderId, $id)); } /** * @NoAdminRequired + * @TrapError * * @param int $accountId * @param string $folderId @@ -190,23 +186,18 @@ class MessagesController extends Controller { * @return JSONResponse */ public function move($accountId, $folderId, $id, $destAccountId, $destFolderId) { - try { - $srcAccount = $this->accountService->find($this->currentUserId, $accountId); - $dstAccount = $this->accountService->find($this->currentUserId, - $destAccountId); - $this->mailManager->moveMessage($srcAccount, base64_decode($folderId), $id, - $dstAccount, base64_decode($destFolderId)); - } catch (ServiceException $ex) { - return new JSONResponse([ - 'error' => $ex->getMessage(), - ], 500); - } + $srcAccount = $this->accountService->find($this->currentUserId, $accountId); + $dstAccount = $this->accountService->find($this->currentUserId, + $destAccountId); + $this->mailManager->moveMessage($srcAccount, base64_decode($folderId), $id, + $dstAccount, base64_decode($destFolderId)); return new JSONResponse(); } /** * @NoAdminRequired * @NoCSRFRequired + * @TrapError * * @param int $accountId * @param string $folderId @@ -256,6 +247,7 @@ class MessagesController extends Controller { /** * @NoAdminRequired * @NoCSRFRequired + * @TrapError * * @param int $accountId * @param string $folderId @@ -275,6 +267,7 @@ class MessagesController extends Controller { /** * @NoAdminRequired + * @TrapError * * @param int $accountId * @param string $folderId @@ -314,12 +307,12 @@ class MessagesController extends Controller { $newFile = $this->userFolder->newFile($fullPath); $newFile->putContent($attachment->getContents()); } - return new JSONResponse(); } /** * @NoAdminRequired + * @TrapError * * @param int $accountId * @param string $folderId @@ -338,12 +331,12 @@ class MessagesController extends Controller { } $mailBox->setMessageFlag($messageId, '\\' . $flag, $value); } - return new JSONResponse(); } /** * @NoAdminRequired + * @TrapError * * @param int $accountId * @param string $folderId @@ -359,7 +352,7 @@ class MessagesController extends Controller { } catch (DoesNotExistException $e) { $this->logger->error("could not delete message <$id> of folder <$folderId>, " . "account <$accountId> because it does not exist"); - return new JSONResponse([], Http::STATUS_NOT_FOUND); + throw $e; } } |