-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCustomDashboardController.cs
27 lines (23 loc) · 1.18 KB
/
CustomDashboardController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using System.Net;
using System.Web.Mvc;
using DevExpress.DashboardWeb.Mvc;
namespace MvcThrowCustomExceptionDashboardErrorToast.Controllers {
public class CustomDashboardController : DashboardController {
protected override void OnException(ExceptionContext context) {
var exception = context.Exception;
if(exception != null && context.HttpContext != null) {
var response = context.HttpContext.Response;
response.StatusCode = (int)HttpStatusCode.BadRequest;
response.ContentType = "application/json";
CustomException customException = exception as CustomException;
bool isCustomErrorsEnabled = System.Web.HttpContext.Current != null ? System.Web.HttpContext.Current.IsCustomErrorEnabled : true;
string message = customException != null ? (isCustomErrorsEnabled ? CustomException.SafeMessage : CustomException.UnsafeMessage) : "";
response.Write(GetJson(message));
context.ExceptionHandled = true;
}
}
static string GetJson(string message) {
return $"{{ \"Message\":\"{message}\" }}";
}
}
}