Skip to content
This repository was archived by the owner on Jul 15, 2021. It is now read-only.

Commit 7dd773d

Browse files
committed
Fixed issue with error, for stopwatch subscriber
1 parent 8b80728 commit 7dd773d

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

dist/GuzzleHttp/Subscriber/StopwatchSubscriber.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use GuzzleHttp\Event\CompleteEvent;
1515
use GuzzleHttp\Event\BeforeEvent;
16+
use GuzzleHttp\Event\ErrorEvent;
1617
use GuzzleHttp\Event\RequestEvents;
1718
use GuzzleHttp\Event\SubscriberInterface;
1819
use Symfony\Component\Stopwatch\Stopwatch;
@@ -36,7 +37,7 @@ public function getEvents()
3637
return [
3738
'before' => ['onBefore', RequestEvents::EARLY],
3839
'complete' => ['onFinish', RequestEvents::LATE],
39-
'error' => ['onFinish', RequestEvents::EARLY],
40+
'error' => ['onError', RequestEvents::EARLY],
4041
];
4142
}
4243

@@ -55,4 +56,15 @@ public function onFinish(CompleteEvent $event)
5556

5657
$this->stopwatch->stop($url);
5758
}
59+
60+
public function onError(ErrorEvent $event)
61+
{
62+
$url = $event->getRequest()->getUrl();
63+
64+
if (!$this->stopwatch->isStarted($url)) {
65+
return;
66+
}
67+
68+
$this->stopwatch->stop($url);
69+
}
5870
}

0 commit comments

Comments
 (0)