Пример #1
0
 public static StockCoreLightweightException Load(this StockCoreLightweightException item, StockCoreException ex)
 {
     if (ex != null)
     {
         item.ID         = ex.ID;
         item.ModuleName = ex.ModuleName;
         item.Info       = ex.Info;
         item.ErrorID    = ex.ErrorID;
     }
     return(item);
 }
Пример #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            app.UseExceptionHandler(builder =>
            {
                builder.Run(async context =>
                {
                    context.Response.StatusCode  = (int)HttpStatusCode.InternalServerError;
                    context.Response.ContentType = "application/json";
                    var ex = context.Features.Get <IExceptionHandlerFeature>();
                    if (ex != null)
                    {
                        StockCoreLightweightException newEx = null;
                        if (ex.Error is StockCoreException)
                        {
                            newEx = new StockCoreLightweightException().Load((StockCoreException)ex.Error);
                        }
                        else
                        {
                            newEx = new StockCoreLightweightException().Load(new StockCoreException(PROCESSID, "", ex.Error, info: "Web Api Global Error catch"));
                        }
                        var info = new Info()
                        {
                            RequestID = Guid.NewGuid().ToString(),
                            Code      = (int)HttpStatusCode.InternalServerError,
                            HasError  = true,
                            Exception = newEx
                        };
                        var data = new Data <string>()
                        {
                            Content = "",
                            Info    = info
                        };
                        var err = JsonConvert.SerializeObject(data);
                        await context.Response.Body.WriteAsync(Encoding.ASCII.GetBytes(err), 0, err.Length).ConfigureAwait(false);
                    }
                });
            }
                                    );

            app.UseMvc();
        }
Пример #3
0
        private StockCoreLightweightException getException(string methodName, Exception ex)
        {
            StockCoreLightweightException exception = null;

            if (ex != null)
            {
                StockCoreException e = null;
                if (ex is StockCoreException)
                {
                    e         = (StockCoreException)ex;
                    exception = new StockCoreLightweightException().Load(e);
                }
                else
                {
                    e         = new StockCoreException(processID, methodName, ex, info: "Capture at Web API level");
                    exception = new StockCoreLightweightException().Load(e);
                }
                determineError(e);
            }
            return(exception);
        }