aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/DevHive.Web/Controllers/ErrorController.cs43
-rw-r--r--src/DevHive.code-workspace3
2 files changed, 38 insertions, 8 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
+ };
}
}
}
diff --git a/src/DevHive.code-workspace b/src/DevHive.code-workspace
index b93bfbc..9ee0259 100644
--- a/src/DevHive.code-workspace
+++ b/src/DevHive.code-workspace
@@ -29,6 +29,7 @@
"**/obj": true,
".gitignore" : true,
},
- "code-runner.fileDirectoryAsCwd": true
+ "code-runner.fileDirectoryAsCwd": true,
+ "compile-hero.disable-compile-files-on-did-save-code": true
}
}