Added CORS handling for errors.