Skip to content

Commit 43cd505

Browse files
authored
Catch failures while transforming the Symfony request into a PSR-7 request in RequestFetcher (#472)
1 parent 32fce0e commit 43cd505

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changelog
22

33
## Unreleased
4+
- Avoid failures when the `RequestFetcher` fails to translate the `Request` (#472)
45

56
## 4.0.3 (2021-03-03)
67
- Fix regression from #454 for `null` value on DSN not disabling Sentry (#457)
@@ -46,7 +47,7 @@ using an on-premise installation it requires Sentry version `>= v20.6.0` to work
4647

4748
- Use `jean85/pretty-package-versions` `^1.5` to leverage the new `getRootPackageVersion` method (c8799ac)
4849
- Fix support for PHP preloading (#354, thanks to @annuh)
49-
- Fix `capture_soft_fails: false` option for the Messenger (#353)
50+
- Fix `capture_soft_fails: false` option for the Messenger (#353)
5051

5152
## 3.5.1 (2020-05-07)
5253

src/Integration/RequestFetcher.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ public function fetchRequest(): ?ServerRequestInterface
5656
return null;
5757
}
5858

59-
return $this->httpMessageFactory->createRequest($request);
59+
try {
60+
return $this->httpMessageFactory->createRequest($request);
61+
} catch (\Throwable $exception) {
62+
return null;
63+
}
6064
}
6165
}

tests/Integration/RequestFetcherTest.php

+14-1
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,21 @@ public function testFetchRequest(?Request $request, ?ServerRequestInterface $exp
5454
$this->assertSame($expectedRequest, $this->requestFetcher->fetchRequest());
5555
}
5656

57+
public function testFetchRequestFailsSilently(): void
58+
{
59+
$this->requestStack->expects($this->once())
60+
->method('getCurrentRequest')
61+
->willReturn(new Request());
62+
63+
$this->httpMessageFactory->expects($this->once())
64+
->method('createRequest')
65+
->willThrowException(new \Exception());
66+
67+
$this->assertNull($this->requestFetcher->fetchRequest());
68+
}
69+
5770
/**
58-
* @return \Generator<mixed>
71+
* @return \Generator<array{Request|null,ServerRequest|null}>
5972
*/
6073
public function fetchRequestDataProvider(): \Generator
6174
{

0 commit comments

Comments
 (0)