Skip to content

Commit 1ac6ba2

Browse files
Merge pull request #207 from Fitabase/issue206-floorsRequestsThrowWithoutFloorsDevice
Issue206 floors requests throw without floors device
2 parents 86611b8 + acd1070 commit 1ac6ba2

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

Fitbit.Portable/Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ internal class Constants
77
public const string TemporaryCredentialsAccessTokenUri = "oauth/access_token";
88
public const string AuthorizeUri = "oauth/authorize";
99
public const string LogoutAndAuthorizeUri = "oauth/logout_and_authorize";
10+
public const string FloorsUnsupportedOnDeviceError = "Invalid time series resource path: /activities/floors";
1011

1112
public class Headers
1213
{

Fitbit.Portable/FitbitClient.cs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -372,21 +372,37 @@ public async Task<IntradayData> GetIntraDayTimeSeriesAsync(IntradayResourceType
372372
dayAndStartTime.Day == dayAndStartTime.Add(intraDayTimeSpan).Day) //adding the timespan doesn't go in to the next day
373373
{
374374
apiCall = string.Format("/1/user/-{0}/date/{1}/1d/time/{2}/{3}.json",
375-
timeSeriesResourceType.GetStringValue(),
376-
dayAndStartTime.ToFitbitFormat(),
377-
dayAndStartTime.ToString("HH:mm"),
378-
dayAndStartTime.Add(intraDayTimeSpan).ToString("HH:mm"));
375+
timeSeriesResourceType.GetStringValue(),
376+
dayAndStartTime.ToFitbitFormat(),
377+
dayAndStartTime.ToString("HH:mm"),
378+
dayAndStartTime.Add(intraDayTimeSpan).ToString("HH:mm"));
379379
}
380380
else //just get the today data, there was a date specified but the timerange was likely too large or negative
381381
{
382382
apiCall = string.Format("/1/user/-{0}/date/{1}/1d.json",
383-
timeSeriesResourceType.GetStringValue(),
384-
dayAndStartTime.ToFitbitFormat());
383+
timeSeriesResourceType.GetStringValue(),
384+
dayAndStartTime.ToFitbitFormat());
385385
}
386386

387387
apiCall = FitbitClientHelperExtensions.ToFullUrl(apiCall);
388388

389-
HttpResponseMessage response = await HttpClient.GetAsync(apiCall);
389+
HttpResponseMessage response = null;
390+
try
391+
{
392+
response = await HttpClient.GetAsync(apiCall);
393+
}
394+
catch (FitbitRequestException fre)
395+
{
396+
if (fre.ApiErrors.Any(err => err.Message == Constants.FloorsUnsupportedOnDeviceError))
397+
{
398+
return null;
399+
}
400+
else
401+
{
402+
//otherwise, rethrow because we only want to alter behavior for the very specific case above
403+
throw;
404+
}
405+
}
390406
await HandleResponse(response);
391407
string responseBody = await response.Content.ReadAsStringAsync();
392408

0 commit comments

Comments
 (0)