Skip to content

ShareFile.Api.Client.Exceptions.InvalidApiResponseException while calling Delete(Uri).ExecuteAsync(cancellationToken) #60

Description

@vats-ashish

While trying to delete a file uploaded to a folder I made a call Delete() calling like-
await _sfClient.Items.Delete(fileUrl).ExecuteAsync(cancellationToken);
_sfclient is injected into the class and I am authenticating the client right before the Delete call.

The file is getting deleted successfully but after the execution completed I am getting the below exception.

Name $exception
Value {"Unable to retrieve HttpResponseMessage.Content"}
Type ShareFile.Api.Client.Exceptions.InvalidApiResponseException

stacktrace:

   at ShareFile.Api.Client.Requests.Providers.AsyncRequestProvider.HandleNonSuccess(HttpResponseMessage responseMessage, Int32 retryCount, Type expectedType)
   at ShareFile.Api.Client.Requests.Providers.AsyncRequestProvider.HandleResponse(HttpResponseMessage httpResponseMessage, ApiRequest request, Int32 retryCount, Boolean tryResolveUnauthorizedChallenge)
   at ShareFile.Api.Client.Requests.Providers.AsyncRequestProvider.ExecuteAsync(IQuery query, CancellationToken token)
   at MyapplicationNamespace.Services.CitrixService.DeleteShareFileAsync(Uri fileUrl, CancellationToken cancellationToken) 

the API troubleshooting documentation clearly says ,

204 No Content This response is commonly used for DELETE operations, and it indicates that the resource was deleted successfully.

But why this is throwing the exception? this is getting logged in my app insight every time I try to delete the file passing the Uri.

How to just simply delete the file without any exception?

Activity

  1. vats-ashish commented on Nov 22, 2023

    @vats-ashish
    Author

    I figured this out. First get the item by passing the same url and then delete the item by passing the url as, item.url into Delete()
    var fileItem = await _sfClient.Items.Get(fileUrl).ExecuteAsync(cancellationToken); await _sfClient.Items.Delete(item.url).ExecuteAsync(cancellationToken);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions