From 2ef52c746e28f2f667bc9654e3c51b3ed67813f5 Mon Sep 17 00:00:00 2001 From: Peter Leibiger Date: Tue, 5 Jul 2022 20:10:47 +0200 Subject: [PATCH 1/2] Add request instead of response data in DioEventProcessor --- CHANGELOG.md | 6 ++++++ dio/lib/src/dio_event_processor.dart | 5 ++--- dio/test/dio_event_processor_test.dart | 11 +++++++---- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d46fd1051f..fb0a729009 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Fixes + +* Add request instead of response data to `SentryRequest` in `DioEventProcessor` + ## 6.6.2 ### Features diff --git a/dio/lib/src/dio_event_processor.dart b/dio/lib/src/dio_event_processor.dart index 3b3d537337..0f9f2ff71d 100644 --- a/dio/lib/src/dio_event_processor.dart +++ b/dio/lib/src/dio_event_processor.dart @@ -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 @@ -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; diff --git a/dio/test/dio_event_processor_test.dart b/dio/test/dio_event_processor_test.dart index 834cacaf48..a21b749e60 100644 --- a/dio/test/dio_event_processor_test.dart +++ b/dio/test/dio_event_processor_test.dart @@ -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( - 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, { 'foo': 'bar', From 6bb9d465311213a51a7aaff3276d61f50ba5df51 Mon Sep 17 00:00:00 2001 From: Peter Leibiger Date: Tue, 5 Jul 2022 20:19:35 +0200 Subject: [PATCH 2/2] Add PR link to changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb0a729009..6eb7c123aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ### Fixes -* Add request instead of response data to `SentryRequest` in `DioEventProcessor` +* Add request instead of response data to `SentryRequest` in `DioEventProcessor` [#933](https://github.com/getsentry/sentry-dart/pull/933) ## 6.6.2