From e1172821f9e63b0be39a36db1a09946da13839bd Mon Sep 17 00:00:00 2001 From: Martin Ces Date: Thu, 9 Jan 2025 16:49:24 +0100 Subject: [PATCH] Minor changes --- lib/ProductOpener/EnvironmentalImpact.pm | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/ProductOpener/EnvironmentalImpact.pm b/lib/ProductOpener/EnvironmentalImpact.pm index 8fc49f9312422..62c4494c35ac7 100644 --- a/lib/ProductOpener/EnvironmentalImpact.pm +++ b/lib/ProductOpener/EnvironmentalImpact.pm @@ -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( @@ -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) {