Skip to content

Commit

Permalink
Add request instead of response data in DioEventProcessor (#933)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhnroyal authored Jul 20, 2022
1 parent 4ec11a9 commit c32f612
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
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

0 comments on commit c32f612

Please sign in to comment.