Skip to content

Commit

Permalink
Do not limit the error controller to a specific HTTP method
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinchalet committed Sep 1, 2024
1 parent 7aafc92 commit fdca80b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 45 deletions.
22 changes: 10 additions & 12 deletions samples/Dantooine/Dantooine.Server/Controllers/ErrorController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,28 @@
* the license and the contributors participating to this project.
*/

using Dantooine.Server.ViewModels.Shared;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Mvc;
using Dantooine.Server.ViewModels.Shared;

namespace Dantooine.Server.Controllers;

public class ErrorController : Controller
{
[Route("error")]
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true), Route("~/error")]
public IActionResult Error()
{
// If the error was not caused by an invalid
// OIDC request, display a generic error page.
// If the error originated from the OpenIddict server, render the error details.
var response = HttpContext.GetOpenIddictServerResponse();
if (response == null)
if (response is not null)
{
return View(new ErrorViewModel());
return View(new ErrorViewModel
{
Error = response.Error,
ErrorDescription = response.ErrorDescription
});
}

return View(new ErrorViewModel
{
Error = response.Error,
ErrorDescription = response.ErrorDescription
});
return View(new ErrorViewModel());
}
}
22 changes: 10 additions & 12 deletions samples/Matty/Matty.Server/Controllers/ErrorController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,28 @@
* the license and the contributors participating to this project.
*/

using Matty.Server.ViewModels.Shared;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Mvc;
using Matty.Server.ViewModels.Shared;

namespace Matty.Server.Controllers;

public class ErrorController : Controller
{
[Route("error")]
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true), Route("~/error")]
public IActionResult Error()
{
// If the error was not caused by an invalid
// OIDC request, display a generic error page.
// If the error originated from the OpenIddict server, render the error details.
var response = HttpContext.GetOpenIddictServerResponse();
if (response == null)
if (response is not null)
{
return View(new ErrorViewModel());
return View(new ErrorViewModel
{
Error = response.Error,
ErrorDescription = response.ErrorDescription
});
}

return View(new ErrorViewModel
{
Error = response.Error,
ErrorDescription = response.ErrorDescription
});
return View(new ErrorViewModel());
}
}
19 changes: 9 additions & 10 deletions samples/Velusia/Velusia.Client/Controllers/ErrorController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,20 @@ namespace Velusia.Client;

public class ErrorController : Controller
{
[HttpGet, HttpPost, Route("~/error")]
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true), Route("~/error")]
public IActionResult Error()
{
// If the error was not caused by an invalid
// OIDC request, display a generic error page.
// If the error originated from the OpenIddict client, render the error details.
var response = HttpContext.GetOpenIddictClientResponse();
if (response is null)
if (response is not null)
{
return View(new ErrorViewModel());
return View(new ErrorViewModel
{
Error = response.Error,
ErrorDescription = response.ErrorDescription
});
}

return View(new ErrorViewModel
{
Error = response.Error,
ErrorDescription = response.ErrorDescription
});
return View(new ErrorViewModel());
}
}
20 changes: 9 additions & 11 deletions samples/Velusia/Velusia.Server/Controllers/ErrorController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,20 @@ namespace Velusia.Server.Controllers;

public class ErrorController : Controller
{
[Route("error")]
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true), Route("~/error")]
public IActionResult Error()
{
// If the error was not caused by an invalid
// OIDC request, display a generic error page.
// If the error originated from the OpenIddict server, render the error details.
var response = HttpContext.GetOpenIddictServerResponse();
if (response == null)
if (response is not null)
{
return View(new ErrorViewModel());
return View(new ErrorViewModel
{
Error = response.Error,
ErrorDescription = response.ErrorDescription
});
}

return View(new ErrorViewModel
{
Error = response.Error,
ErrorDescription = response.ErrorDescription
});
return View(new ErrorViewModel());
}
}

0 comments on commit fdca80b

Please sign in to comment.