internal async Task WriteErrorResponseAsync(HttpContext httpContext, ODataException oe) { var error = new Error { Code = string.IsNullOrEmpty(oe.ErrorCode) ? Enum.GetName(typeof(ODataExceptionCode), oe.ODataExceptionCode) : oe.ErrorCode, ExceptionType = oe.InnerException?.GetType().Name ?? oe.GetType().Name, Message = new ErrorMessage { Lang = System.Globalization.CultureInfo.CurrentUICulture.Name.ToLower(), Value = SNSR.GetString(oe.Message).Replace(Environment.NewLine, "\\n").Replace('"', ' ').Replace('\'', ' ').Replace(" \\ ", " ") }, InnerError = #if DEBUG new StackInfo { Trace = Utility.CollectExceptionMessages(oe) } #else null #endif }; httpContext.Response.ContentType = "application/json"; httpContext.Response.StatusCode = oe.HttpStatusCode; await WriteErrorAsync(httpContext, error).ConfigureAwait(false); }
internal void WriteErrorResponse(HttpContext context, ODataException oe) { var error = new Error { Code = string.IsNullOrEmpty(oe.ErrorCode) ? Enum.GetName(typeof(ODataExceptionCode), oe.ODataExceptionCode) : oe.ErrorCode, ExceptionType = oe.InnerException?.GetType().Name ?? oe.GetType().Name, Message = new ErrorMessage { Lang = System.Globalization.CultureInfo.CurrentUICulture.Name.ToLower(), Value = SNSR.GetString(oe.Message).Replace(Environment.NewLine, "\\n").Replace('"', ' ').Replace('\'', ' ').Replace(" \\ ", " ") }, InnerError = #if DEBUG new StackInfo { Trace = Utility.CollectExceptionMessages(oe) } #else HttpContext.Current != null && HttpContext.Current.IsDebuggingEnabled ? new StackInfo { Trace = Utility.CollectExceptionMessages(oe) } : null #endif }; context.Response.ContentType = "application/json"; WriteError(context, error); context.Response.StatusCode = oe.HttpStatusCode; context.Response.TrySkipIisCustomErrors = true; }