Skip to content

Commit 38148c2

Browse files
committed
Fixed leaking Guzzle exceptions from the HTTP client
1 parent 5db4090 commit 38148c2

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [1.5.1] - 2025-11-10
11+
### Fixed
12+
- Fixed leaking Guzzle exceptions (e.g. `ConnectException`) from the HTTP client. An exception `UnexpectedErrorException` is thrown instead.
13+
1014
## [1.5.0] - 2024-05-23
1115
### Added
1216
- Added support for content type `noContent`.

src/Http/Middleware/UnexpectedErrorMiddleware.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace SixtyEightPublishers\AmpClient\Http\Middleware;
66

77
use Closure;
8+
use Exception;
89
use GuzzleHttp\Promise\PromiseInterface;
910
use Psr\Http\Message\RequestInterface;
1011
use SixtyEightPublishers\AmpClient\Exception\AmpExceptionInterface;
@@ -27,7 +28,11 @@ public function __invoke(Closure $next): Closure
2728
{
2829
return static function (RequestInterface $request, array $options) use ($next): PromiseInterface {
2930
try {
30-
return $next($request, $options);
31+
return $next($request, $options)->otherwise(static function ($e) {
32+
$throwable = $e instanceof Throwable ? $e : new Exception('Unknown error.');
33+
34+
throw ($throwable instanceof AmpExceptionInterface ? $throwable : new UnexpectedErrorException($throwable));
35+
});
3136
} catch (Throwable $e) {
3237
throw ($e instanceof AmpExceptionInterface ? $e : new UnexpectedErrorException($e));
3338
}

0 commit comments

Comments
 (0)