December 2019
Intermediate to advanced
510 pages
11h 33m
English
What if part of the service throws an exception? Handling exceptions is a crucial part of the development process of services. As we saw in Chapter 7, Filter Pipeline, it is possible to use them to catch exceptions using a filter. Filters are one of the crucial parts of the MVC stack: they act before and after action methods, and they can be used to log exceptions in a single implementation. Let's have a look at JsonExceptionAttribute in Catalog.API again:
using System.Net;using Microsoft.AspNetCore.Hosting;using Microsoft.AspNetCore.Mvc;using Microsoft.AspNetCore.Mvc.Filters;using Microsoft.Extensions.Logging;using Catalog.API.Exceptions;namespace Catalog.API.Filters{ public class JsonExceptionAttribute : TypeFilterAttribute ...