cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Error handling for DQL query client

s_eilmsteiner
Dynatrace Enthusiast
Dynatrace Enthusiast

Hi,
I fetch data via DQL using the queryExecutionClient from @dynatrace-sdk/client-query and I want to handle errors correctly. I know that there is the ErrorResponseDetails, but I don't know how to extract it.

 

 

import {
  ErrorResponseDetails,
  queryExecutionClient,
  QueryResult,
} from '@dynatrace-sdk/client-query';

...

queryExecutionClient
        .queryExecute({
          body: {
            query,
            requestTimeoutMilliseconds: 30000,
          },
          abortSignal,
        })
        .then((response) => {
          setResult(response.result);
          setError(undefined);
        })
        .catch((error) => {
          // How can I get the ErrorResponseDetails
        })
        .finally(() => {
          setLoading(false);
        });

 

 

1 REPLY 1

michal_zawislak
Dynatrace Advisor
Dynatrace Advisor

Hi s_eilmsteiner,

You could try using the util function "isClientRequestError" with the desired type of error or "isErrorEnvelopeError".  It depends on the expected error.

import { queryExecutionClient, ErrorResponseDetails, isClientRequestError, isErrorEnvelopeError } from '@dynatrace-sdk/client-query';

await queryExecutionClient.queryExecute({ ... }).catch((e) => {
  if (isClientRequestError<ErrorResponseDetails>(e)) {
    console.error('ErrorResponseDetails', e);
  }
  // OR
  if (isErrorEnvelopeError(e)) {
    console.error('EnvelopeError', e);
  }
});
Your AutomationEngine ally!

Featured Posts