fix: guard against malformed API response and empty matches list
This commit is contained in:
parent
f308d006e4
commit
c75757a70c
2 changed files with 16 additions and 11 deletions
|
|
@ -53,6 +53,7 @@ def identify(images):
|
|||
if not results:
|
||||
raise PlantNetError('No match found — try a different photo or organ.')
|
||||
|
||||
try:
|
||||
return [
|
||||
{
|
||||
'scientific_name': r['species']['scientificNameWithoutAuthor'],
|
||||
|
|
@ -64,3 +65,5 @@ def identify(images):
|
|||
}
|
||||
for r in results[:5]
|
||||
]
|
||||
except (KeyError, TypeError) as exc:
|
||||
raise PlantNetError('Unexpected API response format.') from exc
|
||||
|
|
|
|||
|
|
@ -63,6 +63,8 @@ def identify_confirm(request):
|
|||
return redirect('identify_upload')
|
||||
|
||||
matches = request.session['identify_matches']
|
||||
if not matches:
|
||||
return redirect('identify_upload')
|
||||
|
||||
if request.method == 'POST':
|
||||
try:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue