Updated code to include try catch block to prevent exception when the env variable is not set.