Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net core 在F中使用asp.net内核和suave自定义错误处理#_Asp.net Core_F#_Kestrel Http Server_Custom Error Handling_Suave - Fatal编程技术网

Asp.net core 在F中使用asp.net内核和suave自定义错误处理#

Asp.net core 在F中使用asp.net内核和suave自定义错误处理#,asp.net-core,f#,kestrel-http-server,custom-error-handling,suave,Asp.net Core,F#,Kestrel Http Server,Custom Error Handling,Suave,这个问题是在这里验证自定义错误处理实现,还是有更好的解决方法 你有没有其他最好的建议 我正在使用Suave与Asp.Net内核和F#中的kestrel服务器构建微服务。 我想为使用微服务RESTfulAPI的客户端添加特定服务器端错误的http状态代码和错误消息 我有以下代码 Startup.fs代码==> member this.Configure(app: IApplicationBuilder, env: IHostingEnvironment, loggerFactory: ILog

这个问题是在这里验证自定义错误处理实现,还是有更好的解决方法

你有没有其他最好的建议

我正在使用Suave与Asp.Net内核和F#中的kestrel服务器构建微服务。 我想为使用微服务RESTfulAPI的客户端添加特定服务器端错误的http状态代码和错误消息

我有以下代码

  • Startup.fs代码==>

      member this.Configure(app: IApplicationBuilder, env: IHostingEnvironment, loggerFactory: ILoggerFactory) = 
    
            app.UseSuaveErrorHandler(ConfigApp.ErrHandler) |> ignore 
            <TODO> 
    

  • InnerMethod fs文件代码摘录

  • 让fngetmacturerinfobyiddal(manufacturerID:string)=
    尝试
    FLOGGER.debug“内部FNGETManufacturerInFobyIDAL方法”
    打印FN“内部FNGETManufacturerInFobyIDAL方法-%s”manufacturerID
    使用session=objSettings.OpenSession()
    //查询数据库
    让manufacturerList=session.Load((manufacturerID))
    manufacturerList.Etag FloLogger.debug“%s”ex.消息
    FloLogger.debug“%s”ex.StackTrace
    让strException=“{\”错误发生…\”:\“错误..\”}+ex.消息
    与链式异常有关的故障
    

    因此,内部方法文件get中的代码引发的异常由Suave错误处理程序处理,它在响应中发送http状态代码和异常消息,如所附屏幕截图所示。 但是Suave提供的服务器错误很少,因此内部错误最适合代码错误

      type ConfigApp () = 
        static member ErrHandler (ex:exn) (message:string) (httpContext:HttpContext) = 
    
        let logRepository = 
        log4net.LogManager.GetRepository(Assembly.GetEntryAssembly()) 
        log4net.Config.XmlConfigurator.Configure(logRepository, 
        FileInfo("log4net.config")) |> ignore 
        FloLogger.debug "Exception= %s" ex.Message 
        FloLogger.debug "Exception= %s" ex.StackTrace 
    
        match ex.Message with 
            | x -> INTERNAL_ERROR ("Custom Error Handler: " + ex.Message) httpContext 
    
       let fnGetManufacturerInfoByIdDAL (manufacturerID:string) = 
       try 
           FloLogger.debug "Inside fnGetManufacturerInfoByIdDAL method" 
           printfn "Inside fnGetManufacturerInfoByIdDAL method - %s" manufacturerID 
           use session = objSettings.OpenSession() 
           // Querying database 
           let manufacturerList = session.Load<Manufacturer>((manufacturerID)) 
           manufacturerList.Etag <- session.Advanced.GetEtagFor(manufacturerList); 
           // disposing the opened db session 
           session.Dispose() 
           manufacturerList 
      with 
          | smilie Exception as ex -> FloLogger.debug "%s" ex.Message 
                                    FloLogger.debug "%s" ex.StackTrace 
                                    let strException = "{\"error occurrred...\":\"error..\"}" + ex.Message 
                                    failwith strException