extract method

  1. @override
Future<Result<T, Rejection>> extract(
  1. Request request
)
override

Produces the value, or the rejection that stops the handler.

Implementation

@override
Future<Result<T, Rejection>> extract(Request request) async {
  final value = request.context[key];
  if (value == null) {
    if (null is T) return Ok(null as T);
    return Err(Rejection.internal('context value "$key" is missing'));
  }
  if (value is! T) {
    return Err(Rejection.internal('context value "$key" is not a $T'));
  }
  return Ok(value as T);
}