How to catch az.sdk.message as the response from SDK

Patnam, Bhavani 0 Reputation points
2023-06-07T14:53:24.53+00:00

Hi,

I am using Azure SDK to create import upate. The SDK methods returns the instance of SyncOverAsyncPoller. In case of exception scenarion AzureException is being thrown.

For example, when I am creating a ImportUpdate for already existing importUpdate, AzureExcpetion with message: "Long running operation failed.". But in the log there is a detailed trace of messages: "az.sdk.message" which clearly shows the failure reason as: "Update with the same identity already exists."

Is there any way, I can catch the exception with the exact message which in my case is "Update with the same identity already exists." Reference of the exact message in logs is given below.

{"az.sdk.message":"HTTP response","contentLength":"574","statusCode":200,"url":"https://adu-poc.api.adu.microsoft.com/deviceUpdate/ADU-POC/updates/operations/7402d8cb-3203-45c6-ba17-5158913f4864?api-version=2022-10-01","durationMs":404,"body":"{"operationId":"7402d8cb-3203-45c6-ba17-5158913f4864","status":"Failed","update":{"updateId":{"provider":"Honeywell","name":"linuxfirmwareVG","version":"8.0"},"friendlyName":"test1_vsgubuntu-187-linuxfirmware.importmanifest.json"},**"error":{"occurredDateTime":"2023-06-07T14:11:23.3390004Z","code":"UpdateAlreadyExists","message":"Update with the same identity already exists."}**,"traceId":"9ae46ce79599e6084c106ffb052dcd8b","lastActionDateTime":"2023-06-07T14:11:23.3425856Z","createdDateTime":"2023-06-07T14:11:21.3349599Z","etag":"\"043eec2b-5112-414b-9e91-b415698b732e\""}"}

Regards,

Bhavani

Azure IoT SDK
Azure IoT SDK
An Azure software development kit that facilitates building applications that connect to Azure IoT services.
222 questions
{count} votes

1 answer

Sort by: Most helpful
  1. LeelaRajeshSayana-MSFT 15,801 Reputation points Microsoft Employee
    2023-06-15T23:34:38.2766667+00:00

    Hi @Patnam, Bhavani Greetings! Welcome to Microsoft forum. Thank you for posting the question here.

    I have looked into the implementation of PoolResponse class and it has implementation of the following two methods.

    /**      
    * Represents the status of the long-running operation at the time the last polling operation finished successfully.      
    * @return A {@link LongRunningOperationStatus} representing the result of the poll operation.      
    */     
    public LongRunningOperationStatus getStatus() {         
        return status;     
    }      
    /**      
    * The value returned as a result of the last successful poll operation. This can be any custom user defined object,      
    * or null if no value was returned from the service.     
    * @return T result of poll operation.      
    */     
    public T getValue() { 
        return value;     
    } 
    
    
    

    I believe we can inspect the type of value being returned from these methods and drill down further to capture the error message we see in the logs.

    For example, pollResponse.getValue().getError().getMessage() or poller.getStatus().getThrowable().getMessage() might give us the error message we are looking for.

    Hope this helps. Please let us know if you need any further assistance on this.


    If the response helped, please do click Accept Answer and Yes for the answer provided. Doing so would help other community members with similar issue identify the solution. I highly appreciate your contribution to the community.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.