title: Healthcheck not working with exception handler .net core 2.2
body: <p>I want to use Healthcheck provided by .NetCore 2.2. Its pretty simple to configure. </p>
  
  <p>Apart from using HealthCheck custom response, I am also using exceptionhandler to customize my exception in ErrorController.</p>
  
  <p>The problem is Healthcheck not working. If any error throws from SQL connection, it goes to Error Controller instead of excecuting my custom response health check message. For simplification i just put only 2 line of code here. My actual code has lot of registration like swagger, autofac, fluentvalidation etc.,</p>
  
  <pre><code>public IServiceProvider ConfigureServices(IServiceCollection services)
  {
      services.AddHealthChecks()
      .AddSqlServer(Configuration["ConnectionStrings:defaultConnection"]);
  }
  </code></pre>
  
  <p>Below is configure part of code, again for simplicity I put less code which is required for this issue.</p>
  
  <pre><code>public void Configure(IApplicationBuilder app, IHostingEnvironment env)
          {
              var healthCheckOptions = new HealthCheckOptions();
              healthCheckOptions.ResultStatusCodes[HealthStatus.Unhealthy] = StatusCodes.Status503ServiceUnavailable;
  
              healthCheckOptions.ResponseWriter = async (context, report) =&gt;
              {
                  var problemDetails = new ProblemDetails
                  {
                      Title = "ProviderUnavailable",
                      Status = (int)report.Status,
                      Detail = "Service is down",
                      Instance = context.TraceIdentifier
                  };
                  await context.Response.WriteAsync(JsonConvert.SerializeObject(problemDetails));
              };
              app.UseHealthChecks("/health", healthCheckOptions);
              if (env.IsDevelopment())
              {
                  app.UseExceptionHandler("/error-local-development");
              }
              else
              {
                  app.UseExceptionHandler("/error");
              }
              app.UseCors(x =&gt; x
                  .AllowAnyOrigin()
                  .AllowAnyMethod()
                  .AllowAnyHeader()
                  .AllowCredentials());
  }
  </code></pre>
  
  <p>and then the error throws in below code if i give wrong sql credentials.</p>
  
  <pre><code>public async Task&lt;PerilsResponse&gt; GetPerilRatingScoringAsync(PerilsRequest request)
          {
              using (var connection = new SqlConnection(_connectionString))
              {
                  await connection.OpenAsync();//Exception throws here.
               }
          }
  </code></pre>
  
  <p><strong>ErrorController.cs:</strong></p>
  
  <pre><code>[Route("/error-local-development")]
          [HttpGet]
          [ApiExplorerSettings(IgnoreApi = true)]
          public IActionResult ErrorLocalDevelopment([FromServices] IHostingEnvironment webHostEnvironment)
          {                
              var feature = HttpContext.Features.Get&lt;IExceptionHandlerPathFeature&gt;();
              var ex = feature?.Error;
              var isDev = webHostEnvironment.IsDevelopment();
              var problemDetails = new ProblemDetails
              {
                  Status = StatusCodes.Status500InternalServerError,
                  Instance = feature?.Path,
                  Title = isDev ? $"{ex?.GetType().Name}: {ex?.Message}" : "An error occurred.",
                  Detail = isDev ? ex?.StackTrace : null,
              };
              return StatusCode(problemDetails.Status.Value, problemDetails);
          }
  </code></pre>
  
  <p>The that exception is captured by middleware ErrorController. What I want is to return custom response which is written in the Configure portion of the code which is not getting called.</p>