Skip to content

Commit 482d100

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 482d100

1 file changed

Lines changed: 25 additions & 15 deletions

File tree

Http/Statement.php

Lines changed: 25 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,30 @@
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;
25+
26+
use function React\Promise\set_rejection_handler;
2427

25-
class Statement
28+
class Statement implements LoggerAwareInterface
2629
{
30+
use LoggerAwareTrait;
31+
2732
/** @var Kernel */
2833
protected $httpKernel;
29-
34+
3035
/**
3136
* $request : Service Request
3237
*
@@ -38,7 +43,7 @@ class Statement
3843
/**
3944
* $error : Error
4045
*
41-
* @var Error
46+
* @var HttpException
4247
* @access protected
4348
*/
4449
protected $error;
@@ -122,7 +127,7 @@ public function setHttpKernel(Kernel $httpKernel): void
122127
{
123128
$this->httpKernel = $httpKernel;
124129
}
125-
130+
126131
/**
127132
*
128133
* @param Request $request An http request object to send
@@ -134,6 +139,12 @@ public function __construct(Request $request, EventDispatcherInterface $eventDis
134139
$this->promise = $this->deferred->promise();
135140
$this->eventDispatcher = $eventDispatcher;
136141
$this->httpKernel = $httpKernel;
142+
143+
if (function_exists('React\Promise\set_rejection_handler')) {
144+
set_rejection_handler(fn(Throwable $e) => $this->logger?->warning(
145+
'Unhandled promise rejection with ' . $e->getMessage(),
146+
));
147+
}
137148
}
138149

139150

@@ -259,7 +270,6 @@ public function json($json = null)
259270
$json = (string) $json;
260271
} else {
261272
$json = json_encode(null);
262-
263273
}
264274
$this->request->setContent($json);
265275
}
@@ -374,7 +384,8 @@ public function attachFile($key, $filepath, $mimetype = null, $clientName = null
374384
$file->getRealPath(),
375385
$clientName,
376386
$file->getMimeType(),
377-
0);
387+
0
388+
);
378389

379390
$this->getRequest()->files->set($key, $file);
380391
}
@@ -447,9 +458,9 @@ public function authorizeOAuth($consumerKey, $consumerSecret)
447458
}
448459

449460
/**
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)
461+
* @param string $key The key
462+
* @param string|array $values The value or an array of values
463+
* @param bool $replace Whether to replace the actual value or not (true by default)
453464
*
454465
* @return self
455466
*/
@@ -458,5 +469,4 @@ public function setHeader($key, $values, $replace = true)
458469
$this->request->headers->set($key, $values, $replace);
459470
return $this;
460471
}
461-
462-
}
472+
}

0 commit comments

Comments
 (0)