blob: 2adc6421cf3eb5a61b336b53de78e7e32f05575e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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(),
];
}
}
|