Skip to content
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

Add request instead of response data in DioEventProcessor #933

Merged
merged 6 commits into from
Jul 20, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

### Fixes

* Add request instead of response data to `SentryRequest` in `DioEventProcessor` [#933](https://github.com/getsentry/sentry-dart/pull/933)
* Context Escape with ScopeCallback ([#925](https://github.com/getsentry/sentry-dart/pull/925))

## 6.6.2
Expand Down
5 changes: 2 additions & 3 deletions dio/lib/src/dio_event_processor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:sentry/sentry.dart';
import 'package:sentry/src/sentry_exception_factory.dart';

/// This is an [EventProcessor], which improves crash reports of [DioError]s.
/// It adds information about [DioError.response] if present and also about
/// It adds information about [DioError.requestOptions] if present and also about
/// the inner exceptions.
class DioEventProcessor implements EventProcessor {
// Because of obfuscation, we need to dynamically get the name
Expand Down Expand Up @@ -120,12 +120,11 @@ class DioEventProcessor implements EventProcessor {
cookies: _options.sendDefaultPii
? options.headers['Cookie']?.toString()
: null,
data: _getRequestData(dioError.response?.data),
data: _getRequestData(dioError.requestOptions.data),
);
}

/// Returns the request data, if possible according to the users settings.
/// Type checks are based on DIOs [ResponseType].
Object? _getRequestData(dynamic data) {
if (!_options.sendDefaultPii) {
return null;
Expand Down
11 changes: 7 additions & 4 deletions dio/test/dio_event_processor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,22 @@ void main() {
test('$DioEventProcessor adds request', () {
final sut = fixture.getSut(sendDefaultPii: true);

final request = requestOptions.copyWith(
method: 'POST',
data: 'foobar',
);
final event = SentryEvent(
throwable: DioError(
requestOptions: requestOptions,
requestOptions: request,
response: Response<dynamic>(
requestOptions: requestOptions,
data: 'foobar',
requestOptions: request,
),
),
);
final processedEvent = sut.apply(event) as SentryEvent;

expect(processedEvent.throwable, event.throwable);
expect(processedEvent.request?.method, 'GET');
expect(processedEvent.request?.method, 'POST');
expect(processedEvent.request?.queryString, 'foo=bar');
expect(processedEvent.request?.headers, <String, String>{
'foo': 'bar',
Expand Down