Particle.ParticleCloud.MakeDeleteRequestWithAuthTestAsync C# (CSharp) Method

MakeDeleteRequestWithAuthTestAsync() public method

Calls MakeDeleteRequestAsync(string) and if it returns a status code of Unauthorized try s to refresh the token and makes the request again
public MakeDeleteRequestWithAuthTestAsync ( String method ) : Task
method String The method to call
return Task
		public virtual async Task<RequestResponse> MakeDeleteRequestWithAuthTestAsync(String method)
		{
			var response = await MakeDeleteRequestAsync(method);
			if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
			{
				await RefreshTokenAsync();
				response = await MakeDeleteRequestAsync(method);
			}

			return response;
		}

Usage Example

示例#1
0
        /// <summary>
        /// Unclaims the Device asynchronous.
        /// </summary>
        /// <returns></returns>
        public async Task <Result> UnclaimAsync()
        {
            try
            {
                var result = await cloud.MakeDeleteRequestWithAuthTestAsync($"devices/{Id}");

                return(result.AsResult());
            }
            catch (HttpRequestException re)
            {
                return(new Result
                {
                    Success = false,
                    Error = re.Message,
                    Exception = re
                });
            }
        }