ProcessWebException method

Future<void> ProcessWebException(
  1. WebException webException
)
Processes the web exception. The web exception.

Implementation

/* private */
Future<void> ProcessWebException(WebException webException) async {
  if (webException.Response != null) {
    IEwsHttpWebResponse httpWebResponse = this
        .Service
        .HttpWebRequestFactory
        .CreateExceptionResponse(webException);
    SoapFaultDetails? soapFaultDetails;

    if (httpWebResponse.StatusCode == HttpStatusCode.InternalServerError) {
      // If tracing is enabled, we read the entire response into a MemoryStream so that we
      // can pass it along to the ITraceListener. Then we parse the response from the
      // MemoryStream.
      if (this.Service.IsTraceEnabledFor(TraceFlags.AutodiscoverRequest)) {
        MemoryStream memoryStream = new MemoryStream();
        Stream serviceResponseStream =
            ServiceRequestBase.GetResponseStream(httpWebResponse);
        // Copy response to in-memory stream and reset position to start.
        await EwsUtilities.CopyStream(
            serviceResponseStream as Stream<List<int>>, memoryStream);
        memoryStream.Position = 0;

        this.Service.TraceResponse(httpWebResponse, memoryStream);

        EwsXmlReader reader =
            await EwsServiceXmlReader.Create(memoryStream, this.Service);
        soapFaultDetails = this.ReadSoapFault(reader);
      } else {
        Stream stream = ServiceRequestBase.GetResponseStream(httpWebResponse);

        EwsXmlReader reader = await EwsServiceXmlReader.Create(
            stream as Stream<List<int>>, this.Service);
        soapFaultDetails = this.ReadSoapFault(reader);
      }

      if (soapFaultDetails != null) {
        throw new ServiceResponseException(
            new ServiceResponse.withSoapFault(soapFaultDetails));
      }
    } else {
      this.Service.ProcessHttpErrorResponse(httpWebResponse, webException);
    }
  }
}