heyuntao
2023-10-07 579e58522c83dfc2fe54f3d0fc225ef12091b269
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
42
43
44
<?php
namespace app\common\exception;
 
 
trait Error
{
    protected $HxError = NULL;
 
 
    /**
     * 设置错误 
     * @param $message
     * @param int $code
     * @return bool
     */
    protected function setError($message, int $code = 1): bool
    {
        if (gettype($message) == 'object')
        {
            if (!($message instanceof ApiException) && $message instanceof \Exception) $message = new ApiException($message->getMessage(), $message->getCode());
        }
        else {
            if (gettype($message) != 'string') $message = (string)$message;
 
            $message = new ApiException($message, $code);
        }
 
        $this->HxError = $message;
 
        return false;
    }
 
 
    /**
     * 获取错误 
     *
     * @return ApiException
     */
    public function getError(): ApiException
    {
        return $this->HxError;
    }
 
}