Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #4 #5

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions maintenance/dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -941,13 +941,12 @@ def harvest_sources_list(self, id_or_name='id'):
{
'fq': '+dataset_type:harvest',
'rows': rows,
'fl': 'id, name',
'start': start
}
)
if not action_success(r):
raise DialogError(
"Impossible de dresser la liste des moissonnages."
f"Impossible de dresser la liste des moissonnages: {extract_error(r)}"
)
l = r.json()['result']['results']
if not l:
Expand Down Expand Up @@ -1354,6 +1353,29 @@ def action_success(action_result):
return False


def extract_error(action_result):
"""Renvoie le message d'erreur correspondant à la réponse.

Parameters
----------
action_result : requests.Response
Le résultat de la requête, tel que renvoyé par
requests.

Returns
-------
str
Message d'erreur.
"""
if action_result.status_code == 200:
json = action_result.json()
if json['success']:
return None
return json['error']
else:
return f"HTTP error {action_result.status_code}"


def json_import(filename):
"""Importe un fichier JSON du répertoire parent du module.

Expand Down