Skip to content

Commit af5a029

Browse files
authored
Adjust false positives from server errors (#30)
* feat: handle HttpException separately in MetricMiddleware Added a catch block for HttpException in MetricMiddleware to treat them as valid HTTP responses, updating request_status label accordingly before ending the timer. This prevents HttpExceptions from being counted as internal errors. * chore: remove close-pull-request and release workflows Deleted GitHub Actions workflows for closing pull requests and handling releases. These workflows are no longer needed or have been moved.
1 parent dfb0870 commit af5a029

File tree

3 files changed

+8
-20
lines changed

3 files changed

+8
-20
lines changed

.github/workflows/close-pull-request.yml

Lines changed: 0 additions & 9 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/Middleware/MetricMiddleware.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
namespace Hyperf\Metric\Middleware;
1414

1515
use Hyperf\Contract\ConfigInterface;
16+
use Hyperf\HttpMessage\Exception\HttpException;
1617
use Hyperf\HttpServer\Router\Dispatched;
1718
use Hyperf\Metric\Metric;
1819
use Hyperf\Metric\Support\Uri;
@@ -59,6 +60,13 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
5960
$timer->end($labels);
6061

6162
return $response;
63+
} catch (HttpException $httpException) {
64+
65+
// HttpExceptions are valid HTTP responses, not internal errors
66+
$labels['request_status'] = (string) $httpException->getStatusCode();
67+
$timer->end($labels);
68+
69+
throw $httpException;
6270
} catch (Throwable $exception) {
6371
$this->countException($request, $exception);
6472
$timer->end($labels);

0 commit comments

Comments
 (0)