blob: 62486593b335b5730c6991c8e866daa8f3443da1 (
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
|
<?php
namespace App\Errors;
use Symfony\Component\HttpFoundation\JsonResponse;
class ErrorResponse extends JsonResponse
{
public function __construct(ErrorCode $code, string $message, int $httpCode)
{
parent::__construct(
[
"errcode" => $code,
"error" => $message,
],
$httpCode
);
}
public static function fromException(Exception $exception): self
{
$self = new self($exception->getErrorCode(), $exception->getMessage(), $exception->getCode());
$self->setData(
json_decode($self->data, true) + $exception->getAdditionalData()
);
return $self;
}
}
|