Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
very-smartin committed Jan 9, 2025
1 parent 761395f commit e117282
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/ProductOpener/EnvironmentalImpact.pm
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ package ProductOpener::EnvironmentalImpact;
use ProductOpener::PerlStandards;
use Exporter qw< import >;

use HTTP::Request::Common;

BEGIN {
use vars qw(@ISA @EXPORT_OK %EXPORT_TAGS);
@EXPORT_OK = qw(
Expand Down Expand Up @@ -168,10 +170,18 @@ sub estimate_environmental_impact_service ($product_ref, $updated_product_fields
) if $log->is_debug();

# Analyser la réponse JSON
my $response_data = decode_json($response->decoded_content);
my $response_data;
eval {
$response_data = decode_json($response->decoded_content);
};
if ($@) {
$log->warn("Invalid JSON response: $@") if $log->is_warn();
return;
}

# Accéder à la valeur spécifique "ecs"
my $ecs_value = $response_data->{results} // {}->{total} // {}->{ecs};
# my $ecs_value = $response_data->{results} // {}->{total} // {}->{ecs};
my $ecs_value = $response_data->{results}{total}{ecs} if exists $response_data->{results}{total}{ecs};

# Vérifier si ecs existe et le stocker dans le champ de produit
if (defined $ecs_value) {
Expand Down

0 comments on commit e117282

Please sign in to comment.