added a json try catch block to return errors