aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Web/Controllers
diff options
context:
space:
mode:
Diffstat (limited to 'src/DevHive.Web/Controllers')
-rw-r--r--src/DevHive.Web/Controllers/ErrorController.cs43
1 files changed, 36 insertions, 7 deletions
diff --git a/src/DevHive.Web/Controllers/ErrorController.cs b/src/DevHive.Web/Controllers/ErrorController.cs
index 19fbb21..67a83fe 100644
--- a/src/DevHive.Web/Controllers/ErrorController.cs
+++ b/src/DevHive.Web/Controllers/ErrorController.cs
@@ -1,17 +1,46 @@
using System;
-using System.Net.Http;
+using System.Diagnostics;
+using Microsoft.AspNetCore.Diagnostics;
+using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
+using Newtonsoft.Json;
namespace DevHive.Web.Controllers
{
- [ApiController]
- [Route("/api/[controller]")]
- public class ErrorController
+ public class ErrorController : ControllerBase
{
- [HttpGet]
- public IActionResult Error(Exception exception)
+ [HttpPost]
+ [Route("/api/Error")]
+ public IActionResult Error()
{
- return new BadRequestObjectResult(exception);
+ //Later for logging
+ string requestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
+
+ IExceptionHandlerFeature exception =
+ HttpContext.Features.Get<IExceptionHandlerFeature>();
+
+ object result = ProcessException(requestId, exception);
+ return new BadRequestObjectResult(JsonConvert.SerializeObject(result));
+ }
+
+ private object ProcessException(string requestId, IExceptionHandlerFeature exception)
+ {
+ switch (exception.Error)
+ {
+ case ArgumentException _:
+ case InvalidOperationException _:
+ return MessageToObject(exception.Error.Message);
+ default:
+ return MessageToObject(null);
+ }
+ }
+
+ private object MessageToObject(string message)
+ {
+ return new
+ {
+ Error = message
+ };
}
}
}