28 Mar 2023 01:53 PM - last edited on 20 Apr 2023 08:37 AM by educampver
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);
});
Solved! Go to Solution.
28 Mar 2023 02:02 PM - last edited on 19 Apr 2023 10:39 AM by educampver
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);
}
});