code: def load_json_or_yaml(string, is_path=False, file_type='json',
                        exception=ScriptWorkerTaskException,
                        message="Failed to load %(file_type)s: %(exc)s"):
      
      if file_type == 'json':
          _load_fh = json.load
          _load_str = json.loads
      else:
          _load_fh = yaml.safe_load
          _load_str = yaml.safe_load
  
      try:
          if is_path:
              with open(string, 'r') as fh:
                  contents = _load_fh(fh)
          else:
              contents = _load_str(string)
          return contents
      except (OSError, ValueError, yaml.scanner.ScannerError) as exc:
          if exception is not None:
              repl_dict = {'exc': str(exc), 'file_type': file_type}
              raise exception(message % repl_dict)
docs: Load json or yaml from a filehandle or string, and raise a custom exception on failure.
  
      Args:
          string (str): json/yaml body or a path to open
          is_path (bool, optional): if ``string`` is a path. Defaults to False.
          file_type (str, optional): either "json" or "yaml". Defaults to "json".
          exception (exception, optional): the exception to raise on failure.
              If None, don't raise an exception.  Defaults to ScriptWorkerTaskException.
          message (str, optional): the message to use for the exception.
              Defaults to "Failed to load %(file_type)s: %(exc)s"
  
      Returns:
          dict: the data from the string.
  
      Raises:
          Exception: as specified, on failure