Made exception catching middleware, and implemented it in the app