def METHOD_NAME(fn,
                not_found_message,
                error_message,
                not_found_exception=_DoNotCatchException,
                non_empty_fn=_is_not_empty):
  """Get an entity using `fn`. If the returning entity is nothing (e.g. None or
    a tuple on Nones), it raises 404.
    Args:
      fn: the function to get an entity. It's a function because fn(..) might
          raise an exception.
      not_found_message: the 404 HTTP error is raised with not_found_message for
          an empty entity.
      error_message: the 500 HTTP error is raised with error_message for any
          other exception from fn(..).
      not_found_exception: the type of exception that will be considered as
          'not found' as opposed to other errors."""
  result = None
  try:
    result = fn()
  except not_found_exception:
    pass
  except Exception:
    raise EarlyExitError(
        '%s (%s: %s)' % (error_message, sys.exc_info()[0], str(
            sys.exc_info()[1])), 500)
  if non_empty_fn(result):
    return result
  raise EarlyExitError(not_found_message, 404)