Fix error handling and add custom error pages for 404 and 500.