I am working on a project in ASP.NET Core 3.1. by using clean architecture which is composed of 4 different layers namely Persistence - Domain - Application - Web.
In the Web layer, I have an Admin area which is going to be made with React and also I have an online store which will be using this Admin area but it will be made as an html online store without using REST API. My REST API routes is like this: localhost:5001/api/v1/...
I wanted to know, how could I make a custom error handling middleware which will be able to send status code and error message as json when there is an error in my REST API service and at the same time, it will be able to send them as html views when there is an error in html pages which don't consume REST APIs.