update attachment

Signed-off-by: Jakob Röhrl <jakob.roehrl@web.de>
This commit is contained in:
Jakob Röhrl
2020-02-21 12:08:24 +01:00
committed by Julius Härtl
parent 1e3ff41cb2
commit 725f99d8b8
6 changed files with 95 additions and 10 deletions

View File

@@ -21,16 +21,24 @@
*
*/
namespace OCA\Deck;
namespace OCA\Deck\Exceptions;
use OCA\Deck\StatusException;
class ConflictException extends \Exception {
class ConflictException extends StatusException {
public function __construct($message) {
private $data;
public function __construct($message, $data = null) {
parent::__construct($message);
$this->data = $data;
}
public function getStatus() {
return 409;
}
public function getData() {
return $this->data;
}
}

View File

@@ -25,6 +25,7 @@ namespace OCA\Deck\Middleware;
use OCA\Deck\Controller\PageController;
use OCA\Deck\StatusException;
use OCA\Deck\Exceptions\ConflictException;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Middleware;
use OCP\AppFramework\Http\JSONResponse;
@@ -63,6 +64,17 @@ class ExceptionMiddleware extends Middleware {
* @throws \Exception
*/
public function afterException($controller, $methodName, \Exception $exception) {
if ($exception instanceof ConflictException) {
if ($this->config->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) {
$this->logger->logException($exception);
}
return new JSONResponse([
'status' => $exception->getStatus(),
'message' => $exception->getMessage(),
'data' => $exception->getData(),
], $exception->getStatus());
}
if ($exception instanceof StatusException) {
if ($this->config->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) {
$this->logger->logException($exception);

View File

@@ -26,6 +26,7 @@ namespace OCA\Deck\Service;
use OC\Security\CSP\ContentSecurityPolicyManager;
use OCA\Deck\Db\Attachment;
use OCA\Deck\StatusException;
use OCA\Deck\Exceptions\ConflictException;
use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\AppFramework\Http\EmptyContentSecurityPolicy;
use OCP\AppFramework\Http\FileDisplayResponse;
@@ -42,7 +43,7 @@ use OCP\IConfig;
use OCP\IL10N;
use OCP\ILogger;
use OCP\IRequest;
use OCP\Deck\ConflictException;
class FileService implements IAttachmentService {
@@ -154,7 +155,7 @@ class FileService implements IAttachmentService {
$folder = $this->getFolder($attachment);
$fileName = $file['name'];
if ($folder->fileExists($fileName)) {
throw new ConflictException('File already exists.');
throw new ConflictException('File already exists.', $attachment);
}
$target = $folder->newFile($fileName);