process method

void process(
  1. dynamic successHandler(
    1. String jwt
    ),
  2. dynamic errorHandler(
    1. MLoginCitError error
    )
)

Convenience function that simplifies working with MLoginCitResults.

Implementation

void process(
  /// Called in case the request was successful
  Function(String jwt) successHandler,

  /// Called in case the request encountered an error
  Function(MLoginCitError error) errorHandler,
) {
  if (this is MLoginCitResultError) {
    errorHandler((this as MLoginCitResultError).error);
  } else if (this is MLoginCitResultSuccess) {
    MLoginCitResultSuccess successResult = this as MLoginCitResultSuccess;
    successHandler(successResult.jwt);
  } else {
    MLoginLog.error(
        'ERROR! Unexpected result type $this. Fallback to unknown error.');
    errorHandler(MLoginCitError.unknown);
  }
}