From middleware:
return httpContext.Response.WriteAsync(new ErrorDTO
{
Message = "Some Message",
Title = "Some Title
}).ToString();
From Controller:
return BadRequest(new ErrorDTO
{
Message = "Some Message",
Title = "Some Title"
});
DTO:
public class ErrorDTO
{
public string Message { get; set; }
public string Title { get; set; }
public override string ToString()
{
return JsonConvert.SerializeObject(this);
}
}
Get back JSON:
{"Message":"Some Message", "Title":"Some Title"}