receiveResponse method

  1. @override
void receiveResponse(
  1. int status_code,
  2. IncomingMessage response, [
  3. void onSuccess()?,
  4. void onFailure()?,
])
override

Implementation

@override
void receiveResponse(int status_code, IncomingMessage response,
    [void Function()? onSuccess, void Function()? onFailure]) {
  if (status_code < 200) {
    switch (state) {
      case TransactionState.TRYING:
      case TransactionState.PROCEEDING:
        stateChanged(TransactionState.PROCEEDING);
        _eventHandlers.emit(
            EventOnReceiveResponse(response: response as IncomingResponse?));
        break;
      default:
        break;
    }
  } else {
    switch (state) {
      case TransactionState.TRYING:
      case TransactionState.PROCEEDING:
        stateChanged(TransactionState.COMPLETED);
        clearTimeout(F);

        if (status_code == 408) {
          _eventHandlers.emit(EventOnRequestTimeout());
        } else {
          _eventHandlers.emit(EventOnReceiveResponse(
              response: response as IncomingResponse?));
        }

        K = setTimeout(() {
          timer_K();
        }, Timers.TIMER_K);
        break;
      case TransactionState.COMPLETED:
        break;
      default:
        break;
    }
  }
}