private static GetUserPhotoResponse GetResultOrDefault(Func <object> serviceResponseFactory) { try { return((GetUserPhotoResponse)serviceResponseFactory()); } catch (ServiceRequestException ex) { // 404 is a valid return code in the case of GetUserPhoto when the photo is // not found, so it is necessary to catch this exception here. WebException webException = ex.InnerException as WebException; if (webException != null) { HttpWebResponse errorResponse = webException.Response as HttpWebResponse; if (errorResponse != null && errorResponse.StatusCode == HttpStatusCode.NotFound) { return(GetUserPhotoRequest.GetNotFoundResponse()); } } throw; } }
/// <summary> private static async Task <GetUserPhotoResponse> GetResultOrDefault(Func <Task <object> > serviceResponseFactory) { try { return((GetUserPhotoResponse) await serviceResponseFactory().ConfigureAwait(false)); } catch (ServiceRequestException ex) { // 404 is a valid return code in the case of GetUserPhoto when the photo is // not found, so it is necessary to catch this exception here. EwsHttpClientException webException = ex.InnerException as EwsHttpClientException; if (webException != null) { var errorResponse = webException.Response; if (errorResponse != null && errorResponse.StatusCode == HttpStatusCode.NotFound) { return(GetUserPhotoRequest.GetNotFoundResponse()); } } throw; } }