2021-11-17 08:36:23 -05:00
|
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
2022-08-22 09:29:38 -04:00
|
|
|
|
using System;
|
2021-11-17 08:36:23 -05:00
|
|
|
|
using Microsoft.AspNetCore.Diagnostics;
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2022-11-14 10:12:52 -05:00
|
|
|
|
using OpenTelemetry.Trace;
|
2021-11-17 08:36:23 -05:00
|
|
|
|
|
|
|
|
|
|
namespace Jupiter.Controllers
|
|
|
|
|
|
{
|
2023-07-27 11:20:47 -04:00
|
|
|
|
[ApiController]
|
|
|
|
|
|
[ApiExplorerSettings(IgnoreApi = true)]
|
|
|
|
|
|
public class ErrorController : ControllerBase
|
|
|
|
|
|
{
|
|
|
|
|
|
[Route("/error")]
|
|
|
|
|
|
public IActionResult Error()
|
|
|
|
|
|
{
|
|
|
|
|
|
IExceptionHandlerFeature? context = HttpContext.Features.Get<IExceptionHandlerFeature>();
|
2021-11-17 08:36:23 -05:00
|
|
|
|
|
2023-07-27 11:20:47 -04:00
|
|
|
|
if (context == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return NoContent();
|
|
|
|
|
|
}
|
2021-11-17 08:36:23 -05:00
|
|
|
|
|
2023-07-27 11:20:47 -04:00
|
|
|
|
// ignore cancelled exceptions from the health checks, that will happen if a health check is started while another is running
|
|
|
|
|
|
// the later will contain a valid result
|
|
|
|
|
|
if (context.Error is OperationCanceledException)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (context.Path.StartsWith("/health", StringComparison.Ordinal))
|
|
|
|
|
|
{
|
|
|
|
|
|
return Ok();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-08-22 09:29:38 -04:00
|
|
|
|
|
2023-07-27 11:20:47 -04:00
|
|
|
|
// add the error to our trace
|
|
|
|
|
|
Tracer.CurrentSpan.SetStatus(Status.Error);
|
|
|
|
|
|
Tracer.CurrentSpan.RecordException(context.Error);
|
2022-10-13 09:36:43 -04:00
|
|
|
|
|
2023-07-27 11:20:47 -04:00
|
|
|
|
return Problem(
|
|
|
|
|
|
detail: context.Error.StackTrace,
|
|
|
|
|
|
title: context.Error.Message);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-11-17 08:36:23 -05:00
|
|
|
|
}
|