aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Web/Controllers/ErrorController.cs
diff options
context:
space:
mode:
authortranstrike <transtrike@gmail.com>2021-01-19 21:21:13 +0200
committertranstrike <transtrike@gmail.com>2021-01-19 21:21:13 +0200
commit661c3194b750e42146e9e28a33da08419b2b2cea (patch)
treee8a81ff8833a3a04610f337613537e9b8bd03455 /src/DevHive.Web/Controllers/ErrorController.cs
parent293b4ed2c24855cf01239c3dd27b93a325e648c3 (diff)
downloadDevHive-661c3194b750e42146e9e28a33da08419b2b2cea.tar
DevHive-661c3194b750e42146e9e28a33da08419b2b2cea.tar.gz
DevHive-661c3194b750e42146e9e28a33da08419b2b2cea.zip
Adjusted custom exception middleware; Removed old Global Exception Handler
Diffstat (limited to 'src/DevHive.Web/Controllers/ErrorController.cs')
-rw-r--r--src/DevHive.Web/Controllers/ErrorController.cs50
1 files changed, 0 insertions, 50 deletions
diff --git a/src/DevHive.Web/Controllers/ErrorController.cs b/src/DevHive.Web/Controllers/ErrorController.cs
deleted file mode 100644
index b187501..0000000
--- a/src/DevHive.Web/Controllers/ErrorController.cs
+++ /dev/null
@@ -1,50 +0,0 @@
-using System;
-using System.Diagnostics;
-using AutoMapper;
-using Microsoft.AspNetCore.Diagnostics;
-using Microsoft.AspNetCore.Http;
-using Microsoft.AspNetCore.Mvc;
-using Newtonsoft.Json;
-
-namespace DevHive.Web.Controllers
-{
- public class ErrorController : ControllerBase
- {
- [HttpPost]
- [Route("/api/Error")]
- public IActionResult Error()
- {
- //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 _:
- case AutoMapperMappingException _:
- case AutoMapperConfigurationException _:
- return MessageToObject(exception.Error.Message);
- default:
- return MessageToObject(null);
- }
- }
-
- private object MessageToObject(string message)
- {
- return new
- {
- Error = message
- };
- }
- }
-}
-