Skip to content

Commit

Permalink
API: send HTTP 404 if note is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
korelstar committed Feb 5, 2020
1 parent 084a542 commit b7617a7
Showing 1 changed file with 17 additions and 6 deletions.
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);
}
}
}

0 comments on commit b7617a7

Please sign in to comment.