send method
Sends an HTTP request and asynchronously returns the response.
Implementers should call BaseRequest.finalize
to get the body of the
request as a ByteStream
. They shouldn't make any assumptions about the
state of the stream; it could have data written to it asynchronously at a
later point, or it could already be closed when it's returned. Any
internal HTTP errors should be wrapped as ClientException
s.
Implementation
@override
Future<StreamedResponse> send(BaseRequest request) async {
// See https://develop.sentry.dev/sdk/event-payloads/breadcrumbs/
var requestHadException = false;
int? statusCode;
String? reason;
final stopwatch = Stopwatch();
stopwatch.start();
try {
final response = await _client.send(request);
statusCode = response.statusCode;
reason = response.reasonPhrase;
return response;
} catch (_) {
requestHadException = true;
rethrow;
} finally {
stopwatch.stop();
var breadcrumb = Breadcrumb(
level: requestHadException ? SentryLevel.error : SentryLevel.info,
type: 'http',
category: 'http',
data: {
'url': request.url.toString(),
'method': request.method,
if (statusCode != null) 'status_code': statusCode,
if (reason != null) 'reason': reason,
'duration': stopwatch.elapsed.toString(),
},
);
_hub.addBreadcrumb(breadcrumb);
}
}