public void Write(MemoryStream stream, NephosErrorDetails errorDetails, Exception errorException, bool useVerboseErrors) { using (XmlWriter xmlWriter = this.CreateXmlWriterAndWriteProcessingInstruction(stream)) { XmlErrorResponseWriter.SerializeXmlError(xmlWriter, errorDetails, errorException, useVerboseErrors); } }
private static void SerializeXmlError(XmlWriter writer, NephosErrorDetails errorDetails, Exception errorException, bool useVerboseErrors) { NephosStatusEntry statusEntry = errorDetails.StatusEntry; writer.WriteStartElement("error", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"); XmlErrorResponseWriter.WriteElementString(writer, "code", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata", statusEntry.StatusId); writer.WriteStartElement("message", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"); writer.WriteAttributeString("xml", "lang", null, "en-US"); writer.WriteString(errorDetails.UserSafeErrorMessage); writer.WriteEndElement(); if (useVerboseErrors) { XmlErrorResponseWriter.SerializeXmlException(writer, errorException); } writer.WriteEndElement(); }
public void Write(MemoryStream stream, NephosErrorDetails errorDetails, Exception errorException, bool useVerboseErrors) { if (stream == null) { throw new ArgumentNullException("stream"); } if (errorDetails == null) { throw new ArgumentNullException("errorDetails"); } string item = null; string str = null; if (errorDetails.ResponseHeaders != null) { item = errorDetails.ResponseHeaders["Content-Type"]; str = errorDetails.ResponseHeaders["DataServiceVersion"]; } if (string.IsNullOrWhiteSpace(item)) { throw new ArgumentException(string.Format("errorDetails should contain a valid value for the key [{0}] in ResponseHeader.", "Content-Type")); } if (string.IsNullOrWhiteSpace(str)) { throw new ArgumentException(string.Format("errorDetails should contain a valid value for the key [{0}] in ResponseHeader.", "MaxDataServiceVersion")); } ODataError oDataError = new ODataError() { ErrorCode = errorDetails.StatusEntry.StatusId, Message = errorDetails.UserSafeErrorMessage, MessageLanguage = "en-US", InnerError = new ODataInnerError(errorException) }; ODataMessageWriterSettings oDataMessageWriterSetting = new ODataMessageWriterSettings() { DisableMessageStreamDisposal = true }; ResponseMessage responseMessage = new ResponseMessage(stream); responseMessage.SetHeader("MaxDataServiceVersion", str); responseMessage.SetHeader("Content-Type", item); using (ODataMessageWriter oDataMessageWriter = new ODataMessageWriter(responseMessage, oDataMessageWriterSetting)) { oDataMessageWriter.WriteError(oDataError, useVerboseErrors); } }
protected override void HandleException(HandleExceptionArgs args) { Exception exception = args.Exception; IStringDataEventStream error = Logger <IRestProtocolHeadLogger> .Instance.Error; object[] logString = new object[] { exception.GetLogString() }; error.Log("TableDataServiceHost.ProcessException. Rethrowing exception: {0}", logString); exception = this.tableProtocolHead.TransformExceptionInternal(exception); if (exception is ArgumentOutOfRangeException) { exception = new TableServiceArgumentOutOfRangeException(exception.Message, exception); } else if (exception is ArgumentException) { exception = new TableServiceArgumentException(exception.Message, exception); } else if (exception is OverflowException) { exception = new TableServiceOverflowException(exception.Message, exception); } else if (exception is UriFormatException) { exception = new TableServiceArgumentException(exception.Message, exception); } NephosErrorDetails errorDetailsForException = this.tableProtocolHead.GetErrorDetailsForException(exception); string userSafeErrorMessage = errorDetailsForException.UserSafeErrorMessage; IUtilityTableDataContext currentDataSource = (IUtilityTableDataContext)this.dataSource.CurrentDataSource; if (this.tableProtocolHead.IsBatchRequest() && currentDataSource.FailedCommandIndex >= 0) { CultureInfo invariantCulture = CultureInfo.InvariantCulture; object[] failedCommandIndex = new object[] { currentDataSource.FailedCommandIndex, userSafeErrorMessage }; userSafeErrorMessage = string.Format(invariantCulture, "{0}:{1}", failedCommandIndex); } args.Exception = new DataServiceException((int)errorDetailsForException.StatusEntry.StatusCodeHttp, errorDetailsForException.StatusEntry.StatusId, userSafeErrorMessage, null, args.Exception); this.tableProtocolHead.OnErrorInAstoriaProcessing(errorDetailsForException); }