diff --git a/composer.json b/composer.json index adf4fb5a37..7fa368c6f4 100644 --- a/composer.json +++ b/composer.json @@ -42,6 +42,7 @@ "vendor-prefixed/swiftmailer" ], "files": [ + "lib/exceptions.php", "lib-3rd-party/ArrayColumn.php", "vendor-prefixed/symfony/polyfill-ctype/bootstrap.php", "vendor-prefixed/symfony/polyfill-iconv/bootstrap.php", diff --git a/lib/exceptions.php b/lib/exceptions.php new file mode 100644 index 0000000000..77a9eb978e --- /dev/null +++ b/lib/exceptions.php @@ -0,0 +1,75 @@ +message = $message; + return $this; + } + + public function withCode(int $code): self { + $this->code = $code; + return $this; + } + + public function withErrors(array $errors): self { + $this->errors = $errors; + return $this; + } + + public function getErrors(): array { + return $this->errors; + } +} + + +/** + * USE: Generic runtime error. When possible, use a more specific exception instead. + */ +class RuntimeException extends Exception {} + + +/** + * USE: When wrong data VALUE is received. + */ +class UnexpectedValueException extends RuntimeException {} + + +/** + * USE: When an action is forbidden for given actor (although generally valid). + */ +class AccessDeniedException extends UnexpectedValueException {} + + +/** + * USE: When the main resource we're interested in doesn't exist. + */ +class NotFoundException extends UnexpectedValueException {} + + +/** + * USE: When the main action produces conflict (i.e. duplicate key). + */ +class ConflictException extends UnexpectedValueException {} + + +/** + * USE: An application state that should not occur. Can be subclassed for feature-specific exceptions. + */ +class InvalidStateException extends RuntimeException {}