Skip to content

Commit daac976

Browse files
committed
fix(exception): 🐛 修正ApiException的header設置無效問題
1 parent 1957e75 commit daac976

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

src/Exceptions/ApiException.php

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,25 @@
1111

1212
abstract class ApiException extends Exception implements HttpExceptionInterface
1313
{
14-
// return api code, override if needed
14+
/**
15+
* return api code, override if needed.
16+
*
17+
* @var int
18+
*/
1519
public const API_CODE = Response::HTTP_INTERNAL_SERVER_ERROR;
1620

17-
// return http code, override if needed
21+
/**
22+
* return http code, override if needed.
23+
*
24+
* @var int
25+
*/
1826
public const HTTP_CODE = Response::HTTP_INTERNAL_SERVER_ERROR;
1927

20-
// return message, override if needed
28+
/**
29+
* return message, override if needed.
30+
*
31+
* @var string
32+
*/
2133
public const API_MESSAGE = '';
2234

2335
/**
@@ -58,13 +70,19 @@ public function render(Request $request): JsonResponse
5870
{
5971
return ApiResponseBuilder::exceptionError(
6072
$this,
61-
static::API_CODE,
62-
static::HTTP_CODE,
73+
$this->getApiCode(),
74+
$this->getStatusCode(),
6375
$this->message,
64-
$this->data
76+
$this->data,
77+
$this->getHeaders(),
6578
);
6679
}
6780

81+
public function getApiCode(): int
82+
{
83+
return static::API_CODE;
84+
}
85+
6886
public function getStatusCode(): int
6987
{
7088
return static::HTTP_CODE;

0 commit comments

Comments
 (0)