Skip to content

Commit

Permalink
Handle case where upgrade fails, do not allow to proceed then.
Browse files Browse the repository at this point in the history
  • Loading branch information
BrendanGrant committed Jan 6, 2019
1 parent cbf6b07 commit 93e73f6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions NOnStar/OnStarClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Threading.Tasks;
using System.Linq;
using NOnStar.CommandAndControl;
using Newtonsoft.Json;

namespace NOnStar
{
Expand Down Expand Up @@ -213,6 +214,13 @@ private async Task Upgrade()

var pinUpgradeResult = await client.PostAsync("https://api.gm.com/api/v1/oauth/token/upgrade", new StringContent(pinToken));
var pinUpgradeResultStr = await pinUpgradeResult.Content.ReadAsStringAsync();

if (pinUpgradeResultStr != string.Empty)
{
var errorMessage = JsonConvert.DeserializeObject<UpgradeError>(pinUpgradeResultStr);

throw new InvalidOperationException($"{errorMessage.Error} - {errorMessage.Description}");
}
}

private async Task<CommandRequestStatus> Login( DeviceAuth authObject)
Expand Down
14 changes: 14 additions & 0 deletions NOnStar/Types/UpgradeError.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace NOnStar.Types
{
public class UpgradeError
{
public string Error { get; set; }
[JsonProperty("error_description")]
public string Description { get; set; }
}
}

0 comments on commit 93e73f6

Please sign in to comment.