void IErrorHandler.ProvideFault(Exception error, MessageVersion version, ref Message fault) { ServiceDiagnostics.ReportUnhandledException(error, HttpContext.Current); string text = HttpContext.Current.Request.QueryString["$format"]; string text2 = HttpContext.Current.Request.Headers["Accept"]; XmlObjectSerializer serializer; WebBodyFormatMessageProperty property; if ((text != null && text.Equals("json", StringComparison.InvariantCultureIgnoreCase)) || (text2 != null && text2.Equals("application/json", StringComparison.InvariantCultureIgnoreCase))) { serializer = new DataContractJsonSerializer(typeof(ServiceFault)); property = new WebBodyFormatMessageProperty(WebContentFormat.Json); } else { serializer = new DataContractSerializer(typeof(ServiceFault)); property = new WebBodyFormatMessageProperty(WebContentFormat.Xml); } fault = Message.CreateMessage(version, string.Empty, new ServiceFault(string.Empty, error), serializer); fault.Properties.Add("WebBodyFormatMessageProperty", property); HttpResponseMessageProperty httpResponseMessageProperty = new HttpResponseMessageProperty(); DataServiceException ex = error as DataServiceException; if (ex != null) { httpResponseMessageProperty.StatusCode = (HttpStatusCode)ex.StatusCode; } else { httpResponseMessageProperty.StatusCode = HttpStatusCode.InternalServerError; } fault.Properties.Add(HttpResponseMessageProperty.Name, httpResponseMessageProperty); }
protected override void HandleException(HandleExceptionArgs args) { base.HandleException(args); ServiceDiagnostics.ReportUnhandledException(args.Exception, HttpContext.Current); }