Skip to content

Commit

Permalink
Subsonic: Fix unhandled exception on deleteBookmark
Browse files Browse the repository at this point in the history
There was an unhandled exception when the Subsonic action
`deleteBookmark` was called for a non-existent bookmark, and this got
logged as an error. This happened because, by convention, the business
layer modules should throw BusinessLayerException in case the requested
item doesn't exist. The SubsonicMiddleware catches such exceptions and
emits the proper Subsonic error response. But BookmarkBusinessLayer was
throwing wrong kind of exception here and it leaked through.

refs #1071
  • Loading branch information
paulijar committed Jun 11, 2023
1 parent f0a3b8d commit cde5d57
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## [Unreleased]

### Added

### Changed

### Fixed
- Subsonic: Unhandled exception when attempting to delete a non-existent bookmark
[#1071](https://github.com/owncloud/music/issues/1071)

## 1.8.4 - 2023-06-06
### Added
- Support for Nextcloud 27 (tested on RC3)
Expand Down
11 changes: 8 additions & 3 deletions lib/BusinessLayer/BookmarkBusinessLayer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
* @author Gavin E <no.emai@address.for.me>
* @author Pauli Järvinen <pauli.jarvinen@gmail.com>
* @copyright Gavin E 2020
* @copyright Pauli Järvinen 2020, 2021
* @copyright Pauli Järvinen 2020 - 2023
*/

namespace OCA\Music\BusinessLayer;

use OCA\Music\AppFramework\BusinessLayer\BusinessLayer;
use OCA\Music\AppFramework\BusinessLayer\BusinessLayerException;
use OCA\Music\AppFramework\Core\Logger;

use OCA\Music\Db\BookmarkMapper;
Expand Down Expand Up @@ -57,9 +58,13 @@ public function addOrUpdate(string $userId, int $type, int $entryId, int $positi

/**
* @param int $type One of [Bookmark::TYPE_TRACK, Bookmark::TYPE_PODCAST_EPISODE]
* @throws DoesNotExistException if such bookmark does not exist
* @throws BusinessLayerException if such bookmark does not exist
*/
public function findByEntry(int $type, int $entryId, string $userId) : Bookmark {
return $this->mapper->findByEntry($type, $entryId, $userId);
try {
return $this->mapper->findByEntry($type, $entryId, $userId);
} catch (DoesNotExistException $ex) {
throw new BusinessLayerException($ex->getMessage());
}
}
}

0 comments on commit cde5d57

Please sign in to comment.