ProcessWebException method
Processes the web exception.
The web exception.
Implementation
/* private */
Future<void> ProcessWebException(WebException webException) async {
IEwsHttpWebResponse httpWebResponse =
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 (Service.IsTraceEnabledFor(TraceFlags.AutodiscoverRequest)) {
MemoryStream memoryStream = 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;
Service.TraceResponse(httpWebResponse, memoryStream);
EwsXmlReader reader = await EwsServiceXmlReader.Create(
memoryStream,
Service,
);
soapFaultDetails = await ReadSoapFault(reader);
} else {
Stream<List<int>> stream = ServiceRequestBase.GetResponseStream(
httpWebResponse,
);
EwsXmlReader reader = await EwsServiceXmlReader.Create(stream, Service);
soapFaultDetails = await ReadSoapFault(reader);
}
if (soapFaultDetails != null) {
throw ServiceResponseException(
ServiceResponse.withSoapFault(soapFaultDetails),
);
}
} else {
Service.ProcessHttpErrorResponse(httpWebResponse, webException);
}
}