Skip to content

Commit 5598b4b

Browse files
catching permission denied exception
1 parent cdf48b9 commit 5598b4b

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

ApiIntegrationMvc/Areas/Admin/Controllers/ErrorController.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
using CentralizedLogging.Sdk.Abstractions;
2+
using Microsoft.AspNetCore.Authorization;
23
using Microsoft.AspNetCore.Mvc;
4+
using SharedLibrary;
5+
using SharedLibrary.Auth;
36
using SharedLibrary.Cache;
47

58
namespace ApiIntegrationMvc.Areas.Admin.Controllers
@@ -12,14 +15,21 @@ public class ErrorController : Controller
1215
private readonly IHttpContextAccessor _http;
1316
public ErrorController(ICentralizedLoggingClient centralizedlogs, ICacheAccessProvider cache, IHttpContextAccessor http) => (_centralizedlogs, _cache, _http) = (centralizedlogs, cache, http);
1417

18+
[Authorize(Policy = PolicyType.WEB_LEVEL)]
1519
public async Task<IActionResult> Index(CancellationToken ct)
1620
{
1721
string token = await _cache.GetAccessTokenAsync(ct);
1822

19-
var result = await _centralizedlogs.GetAllErrorAsync(ct);
20-
21-
22-
return View(result.OrderByDescending(v => v.Id));
23+
try
24+
{
25+
var result = await _centralizedlogs.GetAllErrorAsync(ct);
26+
return View(result.OrderByDescending(v => v.Id));
27+
}
28+
catch (PermissionDeniedException ex) when (ex.StatusCode == 403)
29+
{
30+
TempData["Error"] = "You do not have permission to view system error logs.";
31+
return RedirectToAction("Index", "Home", new { area = "Home" });
32+
}
2333
}
2434
}
2535
}

0 commit comments

Comments
 (0)