Skip to content

Commit

Permalink
Merge pull request #1114 from pkuehnel/feat/improveFleetApiLogging
Browse files Browse the repository at this point in the history
feat(FleetApiService): log response strings on non success status codes
  • Loading branch information
pkuehnel authored Feb 12, 2024
2 parents 1e3b88d + d4c036e commit b9ba733
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions TeslaSolarCharger/Server/Services/TeslaFleetApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ private async Task HandleNonSuccessTeslaApiStatusCodes(HttpStatusCode statusCode
if (statusCode == HttpStatusCode.Unauthorized)
{
logger.LogError(
"Your token or refresh token is invalid. Very likely you have changed your Tesla password.");
"Your token or refresh token is invalid. Very likely you have changed your Tesla password. Response: {responseString}", responseString);
teslaSolarChargerContext.TeslaTokens.Remove(token);
teslaSolarChargerContext.TscConfigurations.Add(new TscConfiguration()
{
Expand All @@ -769,7 +769,7 @@ private async Task HandleNonSuccessTeslaApiStatusCodes(HttpStatusCode statusCode
}
else if (statusCode == HttpStatusCode.Forbidden)
{
logger.LogError("You did not select all scopes, so TSC can't send commands to your car.");
logger.LogError("You did not select all scopes, so TSC can't send commands to your car. Response: {responseString}", responseString);
teslaSolarChargerContext.TeslaTokens.Remove(token);
teslaSolarChargerContext.TscConfigurations.Add(new TscConfiguration()
{
Expand All @@ -779,16 +779,16 @@ private async Task HandleNonSuccessTeslaApiStatusCodes(HttpStatusCode statusCode
else if (statusCode == HttpStatusCode.InternalServerError
&& responseString.Contains("vehicle rejected request: your public key has not been paired with the vehicle"))
{
logger.LogError("Vehicle {vin} is not paired with TSC. Add The public key to the vehicle", vin);
logger.LogError("Vehicle {vin} is not paired with TSC. Add The public key to the vehicle. Response: {responseString}", vin, responseString);
var teslaMateCarId = teslamateContext.Cars.First(c => c.Vin == vin).Id;
var car = teslaSolarChargerContext.Cars.First(c => c.TeslaMateCarId == teslaMateCarId);
car.TeslaFleetApiState = TeslaCarFleetApiState.NotWorking;
}
else
{
logger.LogWarning(
"Staus Code {statusCode} is currently not handled, look into https://developer.tesla.com/docs/fleet-api#response-codes to check status code information",
statusCode);
"Staus Code {statusCode} is currently not handled, look into https://developer.tesla.com/docs/fleet-api#response-codes to check status code information. Response: {responseString}",
statusCode, responseString);
return;
}

Expand Down

0 comments on commit b9ba733

Please sign in to comment.