Created
August 25, 2017 14:34
-
-
Save collinjackson/4e57fe154786641e716fb7abcdc99fcf to your computer and use it in GitHub Desktop.
Example of sentry wrapping http.Client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Non-confidential feedback for Posse | |
class SentryHttpClient extends BaseClient { | |
SentryHttpClient(this._inner); | |
final Client _inner; | |
@override | |
Future<StreamedResponse> send(BaseRequest request) async { | |
try { | |
return _inner.send(request); | |
} catch (error) { | |
final SentryResponse response = await sentryClient.capture( | |
event: new Event( | |
exception: error, | |
tags: { | |
'url': request.url.toString(), | |
'host': request.url.host, | |
'path': request.url.path, | |
}, | |
), | |
); | |
if (!response.isSuccessful) { | |
print('Failed to report to Sentry.io: ${response.error}'); | |
} else { | |
print('Successfully reported network failure'); | |
} | |
return null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment