summaryrefslogtreecommitdiffstats
path: root/lib/Service/Exceptions
diff options
context:
space:
mode:
authorSean Molenaar <sean@seanmolenaar.eu>2021-01-02 17:57:17 +0100
committerSean Molenaar <SMillerDev@users.noreply.github.com>2021-02-13 13:22:57 +0100
commitb4fa772bc5f23f84fc292f5d6bf884543d2bfe51 (patch)
tree8576ad3ea145f3644804e2fd93de462cfc2c2578 /lib/Service/Exceptions
parentceba81060303e49b2617397397f2804516052ec9 (diff)
Remove V1 item API
Signed-off-by: Sean Molenaar <sean@seanmolenaar.eu>
Diffstat (limited to 'lib/Service/Exceptions')
-rw-r--r--lib/Service/Exceptions/ServiceConflictException.php16
-rw-r--r--lib/Service/Exceptions/ServiceException.php25
-rw-r--r--lib/Service/Exceptions/ServiceNotFoundException.php17
-rw-r--r--lib/Service/Exceptions/ServiceValidationException.php16
4 files changed, 55 insertions, 19 deletions
diff --git a/lib/Service/Exceptions/ServiceConflictException.php b/lib/Service/Exceptions/ServiceConflictException.php
index dd6ba03c9..ed3d3a54c 100644
--- a/lib/Service/Exceptions/ServiceConflictException.php
+++ b/lib/Service/Exceptions/ServiceConflictException.php
@@ -13,16 +13,22 @@
namespace OCA\News\Service\Exceptions;
+use Exception;
+use OCP\AppFramework\Db\IMapperException;
+
+/**
+ * Class ServiceConflictException
+ *
+ * @package OCA\News\Service\Exceptions
+ */
class ServiceConflictException extends ServiceException
{
/**
- * Constructor
- *
- * @param string $msg the error message
+ * @inheritDoc
*/
- public function __construct(string $msg)
+ public static function from(IMapperException $exception): ServiceException
{
- parent::__construct($msg);
+ return new self($exception->getMessage(), $exception->getCode(), $exception);
}
}
diff --git a/lib/Service/Exceptions/ServiceException.php b/lib/Service/Exceptions/ServiceException.php
index c5ddddbd9..69b963ab6 100644
--- a/lib/Service/Exceptions/ServiceException.php
+++ b/lib/Service/Exceptions/ServiceException.php
@@ -13,16 +13,35 @@
namespace OCA\News\Service\Exceptions;
-class ServiceException extends \Exception
+use Exception;
+use OCP\AppFramework\Db\IMapperException;
+
+/**
+ * Class ServiceException
+ *
+ * @package OCA\News\Service\Exceptions
+ */
+abstract class ServiceException extends Exception
{
/**
* Constructor
*
* @param string $msg the error message
+ * @param int $code
+ * @param Exception|null $previous
*/
- public function __construct(string $msg)
+ final public function __construct(string $msg, int $code = 0, ?Exception $previous = null)
{
- parent::__construct($msg);
+ parent::__construct($msg, $code, $previous);
}
+
+ /**
+ * Create exception from Mapper exception.
+ *
+ * @param IMapperException|Exception $exception Existing exception
+ *
+ * @return static
+ */
+ abstract public static function from(IMapperException $exception): ServiceException;
}
diff --git a/lib/Service/Exceptions/ServiceNotFoundException.php b/lib/Service/Exceptions/ServiceNotFoundException.php
index 6c68ea6b2..f70706506 100644
--- a/lib/Service/Exceptions/ServiceNotFoundException.php
+++ b/lib/Service/Exceptions/ServiceNotFoundException.php
@@ -13,16 +13,21 @@
namespace OCA\News\Service\Exceptions;
+use Exception;
+use OCP\AppFramework\Db\IMapperException;
+
+/**
+ * Class ServiceNotFoundException
+ *
+ * @package OCA\News\Service\Exceptions
+ */
class ServiceNotFoundException extends ServiceException
{
-
/**
- * Constructor
- *
- * @param string $msg the error message
+ * @inheritDoc
*/
- public function __construct(string $msg)
+ public static function from(IMapperException $exception): ServiceException
{
- parent::__construct($msg);
+ return new self($exception->getMessage(), $exception->getCode(), $exception);
}
}
diff --git a/lib/Service/Exceptions/ServiceValidationException.php b/lib/Service/Exceptions/ServiceValidationException.php
index 8e9dc9fee..c41ce4aac 100644
--- a/lib/Service/Exceptions/ServiceValidationException.php
+++ b/lib/Service/Exceptions/ServiceValidationException.php
@@ -13,16 +13,22 @@
namespace OCA\News\Service\Exceptions;
+use Exception;
+use OCP\AppFramework\Db\IMapperException;
+
+/**
+ * Class ServiceValidationException
+ *
+ * @package OCA\News\Service\Exceptions
+ */
class ServiceValidationException extends ServiceException
{
/**
- * Constructor
- *
- * @param string $msg the error message
+ * @inheritDoc
*/
- public function __construct(string $msg)
+ public static function from(IMapperException $exception): ServiceException
{
- parent::__construct($msg);
+ return new self($exception->getMessage(), $exception->getCode(), $exception);
}
}