final Token token = new Token(accessToken, guestService.getApiKeyAttribute(updateInfo.apiKey, "tokenSecret"));
service.signRequest(token, request);
Response response = request.send();
httpResponseCode = response.getCode();
if (httpResponseCode!=200)
throw new UpdateFailedException("Unexpected response code: " + httpResponseCode);
String json = response.getBody();
JSONObject jsonObject = JSONObject.fromObject(json);
final int withingsStatusCode = jsonObject.getInt("status");
String message = null;
if (withingsStatusCode !=0) {
switch (withingsStatusCode) {
case 247:
message = "247 : The userid provided is absent, or incorrect";
throw new UpdateFailedException(message, true,
ApiKey.PermanentFailReason.unknownReason(message));
case 250:
// 250 : The provided userid and/or Oauth credentials do not match
throw new AuthExpiredException();
case 286:
message = "286 : No such subscription was found";
throw new UpdateFailedException(message, true,
ApiKey.PermanentFailReason.unknownReason(message));
case 293:
message = "293 : The callback URL is either absent or incorrect";
throw new UpdateFailedException(message, true,
ApiKey.PermanentFailReason.unknownReason(message));
case 294:
message = "294 : No such subscription could be deleted";
throw new UpdateFailedException(message, true,
ApiKey.PermanentFailReason.unknownReason(message));
case 304:
message = "304 : The comment is either absent or incorrect";
throw new UpdateFailedException(message, true,
ApiKey.PermanentFailReason.unknownReason(message));
case 305:
// 305: Too many notifications are already set
throw new RateLimitExceededException();
case 342:
message = "342 : The signature (using Oauth) is invalid";
throw new UpdateFailedException( message, true,
ApiKey.PermanentFailReason.unknownReason(message));
case 343:
message = "343 : Wrong Notification Callback Url don't exist";
throw new UpdateFailedException(message, true,
ApiKey.PermanentFailReason.unknownReason(message));
case 601:
// 601: Too Many Requests
throw new RateLimitReachedException();
case 2554:
message = "2554 : Wrong action or wrong webservice";
throw new UpdateFailedException(message, true,
ApiKey.PermanentFailReason.unknownReason(message));
case 2555:
message = "2555 : An unknown error occurred";
throw new UpdateFailedException(message, false,
ApiKey.PermanentFailReason.unknownReason(message));
case 2556:
message = "2556 : Service is not defined";
throw new UpdateFailedException(message, true,
ApiKey.PermanentFailReason.unknownReason(message));
default:
throw new UnexpectedHttpResponseCodeException(withingsStatusCode, "Unexpected status code: " + withingsStatusCode);
}