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[stateKeyFor<T>()];
  if (value == null) {
    return Err(
      Rejection.internal(
        'no $T state is attached; add withState<$T>(...) where the routes '
        'are mounted',
      ),
    );
  }
  if (value is! T) {
    return Err(
        Rejection.internal('the attached $T state has the wrong type'));
  }
  return Ok(value);
}