summaryrefslogtreecommitdiff
path: root/matrix-specification/Errors/Error.php
diff options
context:
space:
mode:
Diffstat (limited to 'matrix-specification/Errors/Error.php')
-rw-r--r--matrix-specification/Errors/Error.php41
1 files changed, 41 insertions, 0 deletions
diff --git a/matrix-specification/Errors/Error.php b/matrix-specification/Errors/Error.php
new file mode 100644
index 0000000..2adc642
--- /dev/null
+++ b/matrix-specification/Errors/Error.php
@@ -0,0 +1,41 @@
+<?php
+
+namespace Matrix\Errors;
+
+use Matrix\Enums\ErrorCode;
+
+abstract class Error extends \RuntimeException implements \JsonSerializable
+{
+ public function __construct(
+ private ErrorCode $errorCode,
+ string $message,
+ int $httpCode
+ )
+ {
+ parent::__construct($message, $httpCode);
+ }
+
+ public function getErrorCode(): ErrorCode
+ {
+ return $this->errorCode;
+ }
+
+ public function getHttpCode(): int
+ {
+ return $this->getCode();
+ }
+
+ /**
+ * @return array<string, mixed>
+ */
+ abstract public function getAdditionalData(): array;
+
+ public function jsonSerialize(): array
+ {
+ return [
+ "errcode" => $this->getErrorCode(),
+ "error" => $this->getMessage(),
+ ...$this->getAdditionalData(),
+ ];
+ }
+}