Skip to content

Commit b3f3c5a

Browse files
committed
feat(exception): ✨ ApiException新增預設錯誤訊息常數
1 parent 83f6707 commit b3f3c5a

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/Exceptions/ApiException.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@
1111

1212
abstract class ApiException extends Exception implements HttpExceptionInterface
1313
{
14+
// return api code, override if needed
1415
public const API_CODE = Response::HTTP_INTERNAL_SERVER_ERROR;
1516

17+
// return http code, override if needed
1618
public const HTTP_CODE = Response::HTTP_INTERNAL_SERVER_ERROR;
1719

20+
// return message, override if needed
21+
public const API_MESSAGE = '';
22+
1823
/**
1924
* message.
2025
*
@@ -33,13 +38,9 @@ public function __construct(string $message = null, $data = null)
3338
{
3439
parent::__construct($message);
3540

36-
if (!is_null($message)) {
37-
$this->message = $message;
38-
}
41+
$this->message = $message ?? static::API_MESSAGE;
3942

40-
if (!is_null($data)) {
41-
$this->data = $data;
42-
}
43+
$this->data = $data;
4344
}
4445

4546
/**

0 commit comments

Comments
 (0)