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 >= 100 && status_code <= 199) {
    switch (state) {
      case TransactionState.PROCEEDING:
        if (!transport!.send(response)) {
          onTransportError();
        }
        last_response = response;
        break;
      default:
        break;
    }
  }

  if (status_code > 100 &&
      status_code <= 199 &&
      state == TransactionState.PROCEEDING) {
    // Trigger the resendProvisionalTimer only for the first non 100 provisional response.
    _resendProvisionalTimer ??= setInterval(() {
      resend_provisional();
    }, Timers.PROVISIONAL_RESPONSE_INTERVAL);
  } else if (status_code >= 200 && status_code <= 299) {
    if (state == TransactionState.PROCEEDING) {
      stateChanged(TransactionState.ACCEPTED);
      last_response = response;
      L = setTimeout(() {
        timer_L();
      }, Timers.TIMER_L);

      if (_resendProvisionalTimer != null) {
        clearInterval(_resendProvisionalTimer);
        _resendProvisionalTimer = null;
      }
    }
    /* falls through */
    if (state == TransactionState.ACCEPTED) {
      // Note that this point will be reached for proceeding state also.
      if (!transport!.send(response)) {
        onTransportError();
        if (onFailure != null) {
          onFailure();
        }
      } else if (onSuccess != null) {
        onSuccess();
      }
    }
  } else if (status_code >= 300 && status_code <= 699) {
    switch (state) {
      case TransactionState.PROCEEDING:
        if (_resendProvisionalTimer != null) {
          clearInterval(_resendProvisionalTimer);
          _resendProvisionalTimer = null;
        }

        if (!transport!.send(response)) {
          onTransportError();
          if (onFailure != null) {
            onFailure();
          }
        } else {
          stateChanged(TransactionState.COMPLETED);
          H = setTimeout(() {
            timer_H();
          }, Timers.TIMER_H);
          if (onSuccess != null) {
            onSuccess();
          }
        }
        break;
      default:
        break;
    }
  }
}