decorate method

Future<Object> decorate({
  1. required Response response,
  2. required Object error,
})

Implementation

Future<Object> decorate({
  required Response response,
  required Object error,
}) async {
  if (!options.enabled) {
    return error;
  }

  final logline = DebugResponseLogline(
    client: client,
    sdkVersion: sdkVersion,
    specVersion: specVersion,
    endpoint: _debugResponseEndpoint(response),
    statusCode: response.statusCode,
    contentType: _debugResponseContentType(response),
    error: error,
    body: Uint8List.fromList(response.bodyBytes),
  );

  String? maintainerLogline;
  Object? maintainerLoglineError;
  if (options.includeMaintainerLogline) {
    try {
      maintainerLogline = await _buildMaintainerLogline(logline);
    } catch (cause) {
      maintainerLoglineError = cause;
    }
  }

  String? diagnosticLogline;
  if (options.includeDiagnosticLogline) {
    diagnosticLogline = logline.marshal(includeBody: true);
  }

  return DebugResponseError(
    error: error,
    endpoint: logline.endpoint,
    showNotice: options.showNotice,
    maintainerLogline: maintainerLogline,
    maintainerLoglineError: maintainerLoglineError,
    diagnosticLogline: diagnosticLogline,
  );
}