Skip to content

Commit

Permalink
Change to only log errors if we have set to rethrow exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
colinnuk committed Apr 9, 2024
1 parent 2fd56d2 commit 4ada501
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions OpenMeteo/OpenMeteoClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,13 @@ public OpenMeteoClient(bool rethrowExceptions, IOpenMeteoLogger? logger = null)
return airQuality;
}
catch (HttpRequestException e)
{
_logger?.Error($"{nameof(OpenMeteoClient)}.GetAirQualityAsync(). Message: {e.Message} StackTrace: {e.StackTrace}");
{
if (_rethrowExceptions)
{
_logger?.Error($"{nameof(OpenMeteoClient)}.GetAirQualityAsync(). Message: {e.Message} StackTrace: {e.StackTrace}");
throw;
}
_logger?.Warning($"{nameof(OpenMeteoClient)}.GetAirQualityAsync(). Message: {e.Message} StackTrace: {e.StackTrace}");
return null;
}
}
Expand Down Expand Up @@ -340,9 +343,13 @@ public string WeathercodeToString(int weathercode)
}
catch (Exception e)
{
_logger?.Error($"{nameof(OpenMeteoClient)}.GetWeatherForecastAsync(). Message: {e.Message} StackTrace: {e.StackTrace}");

if (_rethrowExceptions)
{
_logger?.Error($"{nameof(OpenMeteoClient)}.GetWeatherForecastAsync(). Message: {e.Message} StackTrace: {e.StackTrace}");
throw;
}
_logger?.Warning($"{nameof(OpenMeteoClient)}.GetWeatherForecastAsync(). Message: {e.Message} StackTrace: {e.StackTrace}");
return null;
}

Expand All @@ -364,9 +371,12 @@ public string WeathercodeToString(int weathercode)
}
catch (HttpRequestException e)
{
_logger?.Error($"{nameof(OpenMeteoClient)}.GetGeocodingDataAsync(). Message: {e.Message} StackTrace: {e.StackTrace}");
if (_rethrowExceptions)
{
_logger?.Error($"{nameof(OpenMeteoClient)}.GetGeocodingDataAsync(). Message: {e.Message} StackTrace: {e.StackTrace}");
throw;
}
_logger?.Warning($"{nameof(OpenMeteoClient)}.GetGeocodingDataAsync(). Message: {e.Message} StackTrace: {e.StackTrace}");
return null;
}
}
Expand All @@ -387,9 +397,12 @@ public string WeathercodeToString(int weathercode)
catch (HttpRequestException e)
{
_logger?.Warning($"Can't find elevation for latitude {options.Latitude} & longitude {options.Longitude}. Please make sure that they are valid.");
_logger?.Error($"Error in {nameof(OpenMeteoClient)}.GetElevationAsync(). Message: {e.Message} StackTrace: {e.StackTrace}");
if (_rethrowExceptions)
{
_logger?.Error($"Error in {nameof(OpenMeteoClient)}.GetElevationAsync(). Message: {e.Message} StackTrace: {e.StackTrace}");
throw;
}
_logger?.Warning($"Error in {nameof(OpenMeteoClient)}.GetElevationAsync(). Message: {e.Message} StackTrace: {e.StackTrace}");
return null;
}
}
Expand Down

0 comments on commit 4ada501

Please sign in to comment.