added error logging for 404 and 500 errors