Skip to content

Commit 97c5dfd

Browse files
Yoann MOROCUTTIYoann MOROCUTTI
authored andcommitted
fix: Define set_rejection_handler to log message into monolog instead of using error_log
[symfony-6.4]
1 parent cae80ef commit 97c5dfd

1 file changed

Lines changed: 23 additions & 15 deletions

File tree

Http/Statement.php

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* A statement that prepare a request and execute them.
45
* The statement contains request, response and errors
@@ -7,26 +8,28 @@
78
* Date: 29/05/15
89
* Time: 14:21
910
*/
10-
namespace evaisse\SimpleHttpBundle\Http;
1111

12+
namespace evaisse\SimpleHttpBundle\Http;
1213

1314
use evaisse\SimpleHttpBundle\Http\Exception\RequestNotSentException;
15+
use Psr\Log\LoggerAwareInterface;
16+
use Psr\Log\LoggerAwareTrait;
1417
use React\Promise\Deferred;
1518
use React\Promise\Promise;
16-
17-
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
18-
use Symfony\Component\EventDispatcher\EventDispatcher;
1919
use Symfony\Component\HttpFoundation\File\File;
2020
use Symfony\Component\HttpFoundation\File\UploadedFile;
2121
use Symfony\Component\HttpFoundation\Request;
2222
use Symfony\Component\HttpKernel\Exception\HttpException;
2323
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
24+
use Throwable;
2425

25-
class Statement
26+
class Statement implements LoggerAwareInterface
2627
{
28+
use LoggerAwareTrait;
29+
2730
/** @var Kernel */
2831
protected $httpKernel;
29-
32+
3033
/**
3134
* $request : Service Request
3235
*
@@ -38,7 +41,7 @@ class Statement
3841
/**
3942
* $error : Error
4043
*
41-
* @var Error
44+
* @var HttpException
4245
* @access protected
4346
*/
4447
protected $error;
@@ -122,7 +125,7 @@ public function setHttpKernel(Kernel $httpKernel): void
122125
{
123126
$this->httpKernel = $httpKernel;
124127
}
125-
128+
126129
/**
127130
*
128131
* @param Request $request An http request object to send
@@ -134,6 +137,12 @@ public function __construct(Request $request, EventDispatcherInterface $eventDis
134137
$this->promise = $this->deferred->promise();
135138
$this->eventDispatcher = $eventDispatcher;
136139
$this->httpKernel = $httpKernel;
140+
141+
if (function_exists('\React\Promise\set_rejection_handler')) {
142+
\React\Promise\set_rejection_handler(fn(Throwable $e) => $this->logger?->warning(
143+
'Unhandled promise rejection with ' . $e->getMessage(),
144+
));
145+
}
137146
}
138147

139148

@@ -259,7 +268,6 @@ public function json($json = null)
259268
$json = (string) $json;
260269
} else {
261270
$json = json_encode(null);
262-
263271
}
264272
$this->request->setContent($json);
265273
}
@@ -374,7 +382,8 @@ public function attachFile($key, $filepath, $mimetype = null, $clientName = null
374382
$file->getRealPath(),
375383
$clientName,
376384
$file->getMimeType(),
377-
0);
385+
0
386+
);
378387

379388
$this->getRequest()->files->set($key, $file);
380389
}
@@ -447,9 +456,9 @@ public function authorizeOAuth($consumerKey, $consumerSecret)
447456
}
448457

449458
/**
450-
* @param string $key The key
451-
* @param string|array $values The value or an array of values
452-
* @param bool $replace Whether to replace the actual value or not (true by default)
459+
* @param string $key The key
460+
* @param string|array $values The value or an array of values
461+
* @param bool $replace Whether to replace the actual value or not (true by default)
453462
*
454463
* @return self
455464
*/
@@ -458,5 +467,4 @@ public function setHeader($key, $values, $replace = true)
458467
$this->request->headers->set($key, $values, $replace);
459468
return $this;
460469
}
461-
462-
}
470+
}

0 commit comments

Comments
 (0)