Skip to content

Intercept failures in the RequestFetcher #472

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

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

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

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

## 3.5.1 (2020-05-07)

Expand Down
6 changes: 5 additions & 1 deletion src/Integration/RequestFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public function fetchRequest(): ?ServerRequestInterface
return null;
}

return $this->httpMessageFactory->createRequest($request);
try {
return $this->httpMessageFactory->createRequest($request);
} catch (\Throwable $exception) {
return null;
}
}
}
15 changes: 14 additions & 1 deletion tests/Integration/RequestFetcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,21 @@ public function testFetchRequest(?Request $request, ?ServerRequestInterface $exp
$this->assertSame($expectedRequest, $this->requestFetcher->fetchRequest());
}

public function testFetchRequestFailsSilently(): void
{
$this->requestStack->expects($this->once())
->method('getCurrentRequest')
->willReturn(new Request());

$this->httpMessageFactory->expects($this->once())
->method('createRequest')
->willThrowException(new \Exception());

$this->assertNull($this->requestFetcher->fetchRequest());
}

/**
* @return \Generator<mixed>
* @return \Generator<array{Request|null,ServerRequest|null}>
*/
public function fetchRequestDataProvider(): \Generator
{
Expand Down