add a middleware to process exception for 500 error