Closed
Description
Add a set of new Problem helper methods on ControllerBase
, that populates a ProblemDetails
type with relevant values for simple returning of errors through the MVC response pipeline, e.g.:
private ObjectResult Problem()
{
return Problem(detail: null);
}
private ObjectResult Problem(string detail)
{
var problemDetails = new ProblemDetails
{
Title = "An error occurred while processing your request.",
Detail = detail,
Status = 500
};
problemDetails.Extensions.Add("traceId", Activity.Current?.Id ?? HttpContext.TraceIdentifier);
return Problem(problemDetails);
}
private ObjectResult Problem(ProblemDetails problemDetails)
{
return new ObjectResult(problemDetails) { StatusCode = problemDetails.Status };
}