Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions lib/Controller/NotesApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use OCA\Notes\Service\NotesService;
use OCA\Notes\Service\MetaService;
use OCA\Notes\Service\InsufficientStorageException;
use OCA\Notes\Service\NoteDoesNotExistException;
use OCA\Notes\Db\Note;

/**
Expand Down Expand Up @@ -113,10 +114,14 @@ public function index($exclude = '', $pruneBefore = 0) {
* @return DataResponse
*/
public function get($id, $exclude = '') {
$exclude = explode(',', $exclude);
$note = $this->service->get($id, $this->getUID());
$note = $this->excludeFields($note, $exclude);
return new DataResponse($note);
try {
$exclude = explode(',', $exclude);
$note = $this->service->get($id, $this->getUID());
$note = $this->excludeFields($note, $exclude);
return new DataResponse($note);
} catch (NoteDoesNotExistException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
}


Expand Down Expand Up @@ -164,6 +169,8 @@ public function update($id, $content = null, $category = null, $modified = 0, $f
try {
$note = $this->updateData($id, $content, $category, $modified, $favorite);
return new DataResponse($note);
} catch (NoteDoesNotExistException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
} catch (InsufficientStorageException $e) {
return new DataResponse([], Http::STATUS_INSUFFICIENT_STORAGE);
}
Expand Down Expand Up @@ -197,7 +204,11 @@ private function updateData($id, $content, $category, $modified, $favorite) {
* @return DataResponse
*/
public function destroy($id) {
$this->service->delete($id, $this->getUID());
return new DataResponse([]);
try {
$this->service->delete($id, $this->getUID());
return new DataResponse([]);
} catch (NoteDoesNotExistException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
}
}