Skip to content

Commit

Permalink
note weird JSON response
Browse files Browse the repository at this point in the history
  • Loading branch information
rvosa committed Nov 21, 2024
1 parent 1676f54 commit deb2cc2
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions workflow/scripts/update_BOLD_data.pl
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,18 @@ sub validate_response {
return unless $data;

# Check for API error responses
if (exists $data->{error}) {
# TODO JSON is parsed as an arrayref, not a hashref. Why?
if (ref $data eq 'HASH' and exists $data->{error}) {
$logger->error("API error: $data->{error}");
return;
}

# Validate required fields based on endpoint
if (exists $data->{taxid}) {
if (ref $data eq 'HASH' and exists $data->{taxid}) {
# TaxonSearch response
return unless $data->{taxid} =~ /^\d+$/;
}
elsif (exists $data->{barcodespecimens}) {
elsif (ref $data eq 'HASH' and exists $data->{barcodespecimens}) {
# TaxonData response
for my $field (qw(barcodespecimens specimenrecords publicbins)) {
return unless exists $data->{$field};
Expand Down

0 comments on commit deb2cc2

Please sign in to comment.