Tag Archives: dotnetcore

Using Middleware to trap Exceptions in Asp.Net Core

Recently while working on a project I found myself writing a ton of boilerplate code throughout that looked something like this: private readonly Lazy<JSchema> _newItemSchema = new Lazy<JSchema>(() => Helpers.GetSchema(@"POST-request.json")); [HttpPost] public async Task<IActionResult> AddNewItem() { var requestJson = Request.ParseBodyToObject(_newItemSchema.Value); if (!requestJson.Success) { #if DEBUG return BadRequest(requestJson.Object); #else return BadRequest(); #endif } var newItem =… Read More »