safeInvoke method

Future safeInvoke(
  1. Request req,
  2. String name,
  3. dynamic operation(),
  4. dynamic error(
    1. Exception err
    ),
)

Implementation

Future safeInvoke(Request req, String name, Function() operation,
    Function(Exception err) error) async {
  var correlationId = getCorrelationId(req);

  var timing = instrument(correlationId, name);
  try {
    return await operation();
  } catch (err) {
    instrumentError(correlationId, name, err);

    return await error(ApplicationException().wrap(err));
  } finally {
    timing.endTiming();
  }
}