• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

miaoxing / plugin / 3766633246

pending completion
3766633246

push

github

twinh
feat(plugin): `BasePage` 增加 `pageInit` 事件

0 of 1 new or added line in 1 file covered. (0.0%)

84 existing lines in 24 files now uncovered.

902 of 2275 relevant lines covered (39.65%)

19.29 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Callback/HttpCallback.php
1
<?php
2

3
namespace Miaoxing\Plugin\Callback;
4

5
abstract class HttpCallback
6
{
7
    public const MAX_LOG_LENGTH = 1024;
8

9
    /**
10
     * @param mixed $response
11
     * @param \Wei\Http $http
12
     */
13
    public static function success($response, \Wei\Http $http)
14
    {
15
        $retries = $http->getOption('retries');
×
16
        $leftRetries = $http->getOption('leftRetries');
×
17

18
        if ($retries && $retries != $leftRetries) {
×
19
            // 上报是第几次重试才成功
20
            $curRetry = $retries - $leftRetries;
×
21
            wei()->statsD->increment('http.retries.' . $curRetry . '.success');
×
22
        }
23
    }
24

25
    /**
26
     * cURL请求发送失败的回调,记录错误原因和异常堆栈
27
     *
28
     * @param \Wei\Http $http
29
     */
30
    public static function error(\Wei\Http $http)
31
    {
32
        // 只有重试了仍然错误才记录日志
33
        if ($http->getOption('leftRetries')) {
×
34
            return;
×
35
        }
36

37
        $level = $http->getOption('errorLevel') ?: 'error';
×
38

39
        $response = $http->getResponseText();
×
40
        if (mb_strlen($response) > static::MAX_LOG_LENGTH) {
×
41
            $body = mb_substr($response, 0, static::MAX_LOG_LENGTH) . '...';
×
42
        } else {
43
            $body = $response;
×
44
        }
45

46
        $exception = $http->getErrorException();
×
47
        wei()->logger->log($level, $exception->getMessage(), [
×
48
            'url' => $http->getUrl(),
×
49
            'method' => $http->getMethod(),
×
50
            'data' => $http->getData(),
×
51
            'curlInfo' => $http->getCurlInfo(),
×
52
            'curlOptions' => $http->getOption('curlOptions'),
×
UNCOV
53
            'responseBody' => $body,
×
54
            'code' => $exception->getCode(),
×
UNCOV
55
            'exception' => (string) $exception,
×
UNCOV
56
        ]);
×
57
    }
58
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc