creating a middleware to handle server errors 404 and 500