public static void Register(HttpConfiguration config) { var cors = new EnableCorsAttribute("*", "*", "*"); config.EnableCors(cors); config.MessageHandlers.Add(new PreflightRequestsHandler()); config.AddApiVersioning(o => { o.ReportApiVersions = true; o.AssumeDefaultVersionWhenUnspecified = true; o.DefaultApiVersion = new ApiVersion(1, 0); o.ApiVersionReader = new HeaderApiVersionReader("version"); o.ApiVersionSelector = new CurrentImplementationApiVersionSelector(o); } ); // Web API routes config.MapHttpAttributeRoutes(new CustomDirectRouteProvider()); // Web API configuration and services // Configure Web API to use only bearer token authentication. //config.SuppressDefaultHostAuthentication(); //config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType)); var scope = GlobalConfiguration.Configuration.DependencyResolver.BeginScope(); IGlobalExceptionHandler globalExceptionHandler = scope.GetService(typeof(IGlobalExceptionHandler)) as IGlobalExceptionHandler; IUnhandledExceptionLogger unhandledExceptionLogger = scope.GetService(typeof(IUnhandledExceptionLogger)) as IUnhandledExceptionLogger; RequestResponseHandler messageHandler = scope.GetService(typeof(RequestResponseHandler)) as RequestResponseHandler; config.Services.Replace(typeof(IExceptionHandler), globalExceptionHandler); config.Services.Replace(typeof(IExceptionLogger), unhandledExceptionLogger); config.MessageHandlers.Add(messageHandler); var json = config.Formatters.JsonFormatter; json.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.None; json.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; //config.Formatters.Remove(config.Formatters.XmlFormatter); //Remove XML Formatting from Web API /*config.Routes.MapHttpRoute( * "DefaultApi", * "api/v1/{controller}/{id}", * new { id = RouteParameter.Optional } * );*/ }
public ExceptionHandlingMiddleware(RequestDelegate next, IGlobalExceptionHandler globalExceptionHandler) { this.next = next; this.globalExceptionHandler = globalExceptionHandler; }
public ErrorController(IGlobalExceptionHandler handler) { this.handler = handler; }
public LoadPluginsCommandHandler() { _globalExceptionHandler = ServiceFactory.GetExportedService <IGlobalExceptionHandler>(); }
public static IExceptionHandlingBuilder AddExceptionHandling(this IServiceCollection services, IGlobalExceptionHandler globalExceptionHandler) { var builder = services.AddExceptionHandlingBuilder(); builder.Services.AddSingleton(globalExceptionHandler); return(new ExceptionHandlingBuilder(services)); }
public static Task <GlobalExceptionResponse> BadRequest(this IGlobalExceptionHandler handler, object result) { return(Task.FromResult(new GlobalExceptionResponse(result, 400))); }
public static Task <GlobalExceptionResponse> InternalServerError(this IGlobalExceptionHandler handler, object result) { return(Task.FromResult(new GlobalExceptionResponse(result, 500))); }
public static Task <GlobalExceptionResponse> NotFound(this IGlobalExceptionHandler handler, object result) { return(Task.FromResult(new GlobalExceptionResponse(result, 404))); }
public static Task <GlobalExceptionResponse> UnProcessableEntity(this IGlobalExceptionHandler handler, object result) { return(Task.FromResult(new GlobalExceptionResponse(result, 422))); }