reported method
Records an exchange that was already over when it was reported.
request/response track one this process is watching go out and come back, which is what DevbarHttpClient has in hand. An AppEvent a project reported from its own client has only the outcome, so it lands here in one piece and with no timing.
Implementation
void reported(AppEvent event) {
// The inverse of what `AppEvent.request` composed — a method never holds a
// space. A network event some other constructor made keeps its whole title
// as the path, which is the only honest reading of it.
var split = event.title.indexOf(' ');
var request = NetworkRequest(
_reportedId--,
apiName: null,
requestBody: event.data.isEmpty ? null : event.data,
httpMethod: split < 0 ? '' : event.title.substring(0, split),
path: split < 0 ? event.title : event.title.substring(split + 1),
parameters: const {},
timed: false,
);
if (event.error) {
request.errorResponse = ErrorResponse(
code: int.tryParse(event.detail ?? '') ?? 0,
reason: event.detail ?? '',
message: event.body ?? '',
);
} else {
// Decoded where it parses, so the Response tab shows a tree like it does
// for an exchange this process watched. A report carries its body as
// text; handed to the viewer as text it comes back JSON-encoded a second
// time, as one escaped line.
request.response = _decodedOrRaw(event.body);
}
var requestList = requests.value..add(request);
if (requestList.length > _maxRequest) {
requestList.removeAt(0);
}
requests.add(requestList);
}