public void WriteException(HandleExceptionArgs args) { using (XmlWriter writer = XmlWriter.Create(this.outputStream)) { ErrorHandler.SerializeXmlError(args, writer); } }
/// <summary>Serializes exception information.</summary> /// <param name="args">Description of exception to serialize.</param> public void WriteException(HandleExceptionArgs args) { XmlWriter xmlWriter = XmlWriter.Create(this.writer); ErrorHandler.SerializeXmlError(args, xmlWriter); this.writer.Flush(); }
/// <summary>Serializes exception information.</summary> /// <param name="args">Description of exception to serialize.</param> public void WriteException(HandleExceptionArgs args) { Debug.Assert(args != null, "args != null"); XmlWriter xmlWriter = XmlWriter.Create(this.outputStream); ErrorHandler.SerializeXmlError(args, xmlWriter); xmlWriter.Flush(); }
protected override void HandleException(HandleExceptionArgs args) { base.HandleException(args); HandleExceptionCalls++; args.InstanceAnnotations.Add(new ODataInstanceAnnotation(AnnotationName, AnnotationValue)); args.InstanceAnnotations.Add(new ODataInstanceAnnotation("location.error2", new ODataPrimitiveValue("AdditionalAnnotationValue"))); }
public static void Trace(this HandleExceptionArgs handleExceptionArgs) { string trueStringValue; string falseStringValue; string message = handleExceptionArgs.Exception.Message; Tracer current = TraceHelper.Current; string str = message; int responseStatusCode = handleExceptionArgs.ResponseStatusCode; string responseContentType = handleExceptionArgs.ResponseContentType; if (handleExceptionArgs.ResponseWritten) { trueStringValue = Resources.TrueStringValue; } else { trueStringValue = Resources.FalseStringValue; } if (handleExceptionArgs.UseVerboseErrors) { falseStringValue = Resources.TrueStringValue; } else { falseStringValue = Resources.FalseStringValue; } current.DataServiceProviderHandleException(str, responseStatusCode, responseContentType, trueStringValue, falseStringValue); }
protected override void HandleException(HandleExceptionArgs args) { if (args.Exception is AuthenticationException) { var e = args.Exception; args.Exception = new DataServiceException(400, e.GetType().Name, e.Message, "en-US", e); } }
protected override void HandleException(HandleExceptionArgs args) { if (args.Exception != null) { Logger.Error("Error occurs when execute the odata service : " + args.Exception); args.UseVerboseErrors = false; } }
public void CreateODataErrorFromExceptionArgsShouldCreateODataErrorWithCustomAnnotationsAndInstanceAnnotations() { DataServiceException dse = new DataServiceException(500, "500", "Test message", "en-US", null); HandleExceptionArgs args = new HandleExceptionArgs(dse, responseWritten: false, contentType: "application/json", verboseResponse: true); ODataError error = args.CreateODataError(); error.InstanceAnnotations.As <object>().Should().BeSameAs(args.InstanceAnnotations); }
public Task <bool> HandleExceptionAsync(HandleExceptionArgs args) { ++Calls; TaskCompletionSource <bool> tcs = new TaskCompletionSource <bool>(); tcs.SetResult(Handle); return(tcs.Task); }
protected override void HandleException(HandleExceptionArgs args) { Contract.Assert(args != null); Contract.Assert(args.Exception != null); var handledException = args.Exception.TransformException(WebContainerExtension.DefaultPolicy); throw handledException; }
/// <summary> /// Handles the exception that has occured in data service and log it in trace file. /// </summary> /// <param name="args">The arguments.</param> protected override void HandleException(HandleExceptionArgs args) { Exception dataServiceException = args.Exception.InnerException ?? args.Exception; if (dataServiceException != null) { Globals.TraceMessage(TraceEventType.Error, dataServiceException.ToString(), dataServiceException.Message); } }
protected override void HandleException(HandleExceptionArgs args) { string message = "Message: " + args.Exception.Message; if (args.Exception.InnerException != null) { message += " InnerMessage: " + args.Exception.InnerException.Message; } args.Exception = new DataServiceException(400, "", message, "en-US", args.Exception); }
public Task <bool> HandleExceptionAsync(HandleExceptionArgs args) { var result = args.SupportsRetry && !args.CancellationToken.IsCancellationRequested && args.Request.RequestUri.Equals(Owner.UploadUri) ? OnServerError(args.Request) : false; TaskCompletionSource <bool> tcs = new TaskCompletionSource <bool>(); tcs.SetResult(result); return(tcs.Task); }
/// <summary>Method to handle a data service exception during processing.</summary> /// <param name="args">Exception handling description.</param> public void ProcessException(HandleExceptionArgs args) { processExceptionCalled = true; if (!args.ResponseWritten) { this.ResponseStatusCode = args.ResponseStatusCode; this.ResponseContentType = args.ResponseContentType; } }
protected override void HandleException(HandleExceptionArgs args) { args.Trace(); QuotaSystem.ProcessedRequestHandler(null, null); if (OperationContext.Current != null) { OperationContext.Current.TraceOutgoingMessage(); } base.HandleException(args); }
protected override void HandleException(HandleExceptionArgs args) { base.HandleException(args); Debug.Print("{0} {1} -> {2} {3}", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), args.Exception.GetType().Name, args.Exception.Message); }
public void ProcessException(HandleExceptionArgs args) { if (this.ProcessExceptionCallBack != null) { this.ProcessExceptionCallBack(args); } else { throw new NotImplementedException(); } }
protected override void HandleException(HandleExceptionArgs e) { try { e.UseVerboseErrors = true; } catch (Exception ex) { Console.WriteLine(ex.Message); } }
protected override void HandleException(HandleExceptionArgs args) { APICallLog.Current.DataService.HandleException(this, args); try { base.HandleException(args); } finally { APICallLog.Current.Pop(); } }
protected override void HandleException(HandleExceptionArgs args) { base.HandleException(args); // Rollback UnifOfWork if (this.transaction != null) { this.transaction.Rollback(); } // Wrap exception with DataServiceException to show mean full message }
public void ProcessException(HandleExceptionArgs args) { Parent.Add(new APICallLogEntry("IDataServiceHost.ProcessException", new Dictionary <string, string>() { { "ExceptionType", args.Exception.GetType().ToString() }, { "ExceptionMessage", args.Exception.Message }, { "ResponseContentType", args.ResponseContentType.ToString() }, { "ResponseStatusCode", args.ResponseStatusCode.ToString() }, { "ResponseWritten", args.ResponseWritten.ToString() }, { "UseVerboseErrors", args.UseVerboseErrors.ToString() } })); }
public void HandleException <T>(DataService <T> service, HandleExceptionArgs args) { Parent.Add(new APICallLogEntry(service.GetType().Name + "." + "HandleException", new Dictionary <string, string>() { { "ExceptionType", args.Exception.GetType().ToString() }, { "ExceptionMessage", args.Exception.Message }, { "ResponseContentType", args.ResponseContentType.ToString() }, { "ResponseStatusCode", args.ResponseStatusCode.ToString() }, { "ResponseWritten", args.ResponseWritten.ToString() }, { "UseVerboseErrors", args.UseVerboseErrors.ToString() } })); }
protected override void HandleException(HandleExceptionArgs args) { // Handle exceptions raised in service operations. if (args.Exception is TargetInvocationException && args.Exception.InnerException != null) { var exception = args.Exception.InnerException as DataServiceException; args.Exception = exception ?? new DataServiceException(400, "" + args.Exception.InnerException.Message); } else { var msg = GetRealMessageFromException(args.Exception); args.Exception = new DataServiceException(400, msg); } base.HandleException(args); }
/// <summary> /// Handles the exception. /// </summary> /// <param name="args">The args.</param> protected override void HandleException(HandleExceptionArgs args) { string errorMessage = args.Exception.Message; var exception = args.Exception; if (exception.InnerException != null) { exception = exception.InnerException; errorMessage += " " + exception.Message; } var dbEntityValidationException = exception as DbEntityValidationException; if (dbEntityValidationException != null) { errorMessage = errorMessage + " " + String.Join(" ", dbEntityValidationException.EntityValidationErrors.First().ValidationErrors); } args.Exception = new DataServiceException(500, errorMessage); }
/// <summary> /// 重写 HandleException 方法来抛出 400 Bad Request 错误到客户端。 /// </summary> /// <param name="args">HandleException 方法的参数</param> protected override void HandleException(HandleExceptionArgs args) { // 检查是否内部异常为空 null。 if (args.Exception.InnerException != null) { // 把内部异常转化为 DataServiceException DataServiceException ex = args.Exception.InnerException as DataServiceException; // 检查是否内部异常的类型为 DataServiceException // 并且 状态代码为 400(Bad Request) if (ex != null && ex.StatusCode == 400) { // 将 DataServiceException 返回给客户端。 args.Exception = ex; } } base.HandleException(args); }
public void ResponseStatusCodeIsNotSetOnHostAfterProcessRequestWith404Error() { HandleExceptionArgs exceptionArgs = null; var host = new DataServiceHostSimulator { AbsoluteRequestUri = new Uri("http://example.com/invalid"), AbsoluteServiceUri = new Uri("http://example.com/"), RequestHttpMethod = "GET", ResponseStream = new MemoryStream(), ProcessExceptionCallBack = (args) => { exceptionArgs = args; } }; var svc = new TestService(); svc.AttachHost(host); svc.ProcessRequest(); //// Astoria Server fails to set IDSH.ResponseStatusCode for custom hosts in an error scenario //// The behavior has been this way from V2 of WCF Data Services and on, when this is changed //// it will be a breaking change host.ResponseStatusCode.Should().Be(0); host.ResponseStream.Position = 0; var customerResponse = new StreamReader(host.ResponseStream).ReadToEnd(); customerResponse.Should().Contain("Resource not found for the segment 'invalid'."); exceptionArgs.ResponseStatusCode.Should().Be(404); }
/// <summary> /// Override the HandleException method to throw 400 Bad Request /// exception to the client side. /// </summary> /// <param name="args">The HandleException argument</param> protected override void HandleException(HandleExceptionArgs args) { // Check if the InnerException is null if (args.Exception.InnerException != null) { // Convert the InnerException to DataServiceException DataServiceException ex = args.Exception.InnerException as DataServiceException; // Check if the InnerException is in type of // DataServiceException and the StatusCode is // 400(Bad Request) if (ex != null && ex.StatusCode == 400) { // Return the DataServiceException to the client args.Exception = ex; } } base.HandleException(args); }
protected override void HandleException(HandleExceptionArgs args) { // turn unexpected errors into generic 500 error response if (args.Exception != null && args.Exception.InnerException != null && args.Exception.InnerException is RuleEngine.Common.OversizedPayloadException) { // turn an over-sized payload exception into HTTP error 509 Bandwidth Limit Exceeded throw new DataServiceException(509, args.Exception.InnerException.Message); } else if (args.Exception != null && args.Exception.InnerException != null && args.Exception.InnerException is System.ArgumentException) { if (((System.ArgumentException)args.Exception.InnerException).ParamName.Equals("destination", StringComparison.OrdinalIgnoreCase)) { // turn this ArgumentException exception (thrown for unregistered uri schema) into HTTP error 403 Forbidden throw new DataServiceException(403, args.Exception.InnerException.Message); } } if (args.Exception.GetType() != typeof(DataServiceException)) { throw new DataServiceException(500, "Oops. An unexpected error occurred while trying to validate your OData endpoint."); } }
//</snippetChangeInterceptor> //<snippetHandleExceptions> // Override to manage returned exceptions. protected override void HandleException(HandleExceptionArgs args) { // Handle exceptions raised in service operations. if (args.Exception.GetType() == typeof(TargetInvocationException) && args.Exception.InnerException != null) { if (args.Exception.InnerException.GetType() == typeof(DataServiceException)) { // Unpack the DataServiceException. args.Exception = args.Exception.InnerException as DataServiceException; } else { // Return a new DataServiceException as "400: bad request." args.Exception = new DataServiceException(400, args.Exception.InnerException.Message); } } }
/// <summary> /// Generic exception handler. /// </summary> /// <param name="args"></param> protected override void HandleException(HandleExceptionArgs args) { Exception exception = args.Exception; Exception innerException = exception.InnerException; if (exception is TargetInvocationException && innerException != null) { if (innerException is DataServiceException) { args.Exception = innerException; } else { args.Exception = new DataServiceException(400, innerException.Message); } Log.Error(innerException); } else { Log.Error(exception); } }
/// <summary>Serializes exception information.</summary> /// <param name="args">Description of exception to serialize.</param> public void WriteException(HandleExceptionArgs args) { ErrorHandler.SerializeXmlError(args, this.writer); }
/// <summary>Serializes exception information.</summary> /// <param name="args">Description of exception to serialize.</param> public override void WriteException(HandleExceptionArgs args) { ErrorHandler.SerializeJsonError(args, this.writer); }