def _format_payload(success, error_msg=None, artifacts_info=None):
    """Generates the payload dictionary for the job

    Parameters
    ----------
    success : bool
        Whether if the job completed successfully or not
    error_msg : str, optional
        If `success` is False, ther error message to include in the optional.
        If `success` is True, it is ignored
    artifacts_info : list of ArtifactInfo, optional
        The list of output artifact information

    Returns
    -------
    dict
        Format:
        {'success': bool,
         'error': str,
         'artifacts': dict of {str: {'artifact_type': str,
                                     'filepaths': list of (str, str),
                                     'archive': {str: str}}}
    """
    if success and artifacts_info:
        artifacts = {
            a_info.output_name: {'artifact_type': a_info.artifact_type,
                                 'filepaths': a_info.files,
                                 'archive': a_info.archive}
            for a_info in artifacts_info}
    else:
        artifacts = None

    payload = {'success': success,
               'error': error_msg if not success else '',
               'artifacts': artifacts}
    return payload