<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: client-state SDK: informations about error being thrown in Developer Q&amp;A Forum</title>
    <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/client-state-SDK-informations-about-error-being-thrown/m-p/218668#M416</link>
    <description>&lt;P&gt;I'm not sure what the isErrorResponseError function looks like, but basically it looks correct and something as below would work&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;   return stateClient
      .getAppState(...)
      .then(...)
      .catch((err) =&amp;gt; {
        const status = e?.response?.status;
        if (status &amp;amp;&amp;amp; status === 404) {
          // key not set
        } else {
          throw err;
        }
      });&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alternatively, if the non-existence of a certain queried app state is a genuine scenario that you want to cover in your app you could also handle this without explicit error handling logic (as explained in&amp;nbsp;&amp;nbsp;&lt;A href="https://developer.dynatrace.com/develop/data/state/#filter-states" target="_blank" rel="noopener"&gt;https://developer.dynatrace.com/develop/data/state/#filter-states&lt;/A&gt;&amp;nbsp;) via&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;const oneElementOrEmpty: Array&amp;lt;{ key: string, value: string }&amp;gt; = await stateClient.getAppStates({
  filter: "key = 'might-not-exist'",
  add-fields: "value",
});&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and build your logic based on empty/non-empty-array result.&lt;/P&gt;</description>
    <pubDate>Mon, 20 Nov 2023 10:36:35 GMT</pubDate>
    <dc:creator>gregor_riegler</dc:creator>
    <dc:date>2023-11-20T10:36:35Z</dc:date>
    <item>
      <title>client-state SDK: informations about error being thrown</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/client-state-SDK-informations-about-error-being-thrown/m-p/218661#M415</link>
      <description>&lt;P&gt;When using the client-state SDK, what is the best way to see when a key is not set vs when there are other issues? Would the snippet below be the right answer?&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;    return stateClient
      .getAppState(...)
      .then(...)
      .catch((err) =&amp;gt; {
        if (isErrorResponseError(err) &amp;amp;&amp;amp; err.response.status === 404) {
          // key not set
        } else {
          throw err;
        }
      });&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jul 2023 13:08:29 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/client-state-SDK-informations-about-error-being-thrown/m-p/218661#M415</guid>
      <dc:creator>david_petroni</dc:creator>
      <dc:date>2023-07-20T13:08:29Z</dc:date>
    </item>
    <item>
      <title>Re: client-state SDK: informations about error being thrown</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/client-state-SDK-informations-about-error-being-thrown/m-p/218668#M416</link>
      <description>&lt;P&gt;I'm not sure what the isErrorResponseError function looks like, but basically it looks correct and something as below would work&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;   return stateClient
      .getAppState(...)
      .then(...)
      .catch((err) =&amp;gt; {
        const status = e?.response?.status;
        if (status &amp;amp;&amp;amp; status === 404) {
          // key not set
        } else {
          throw err;
        }
      });&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alternatively, if the non-existence of a certain queried app state is a genuine scenario that you want to cover in your app you could also handle this without explicit error handling logic (as explained in&amp;nbsp;&amp;nbsp;&lt;A href="https://developer.dynatrace.com/develop/data/state/#filter-states" target="_blank" rel="noopener"&gt;https://developer.dynatrace.com/develop/data/state/#filter-states&lt;/A&gt;&amp;nbsp;) via&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;const oneElementOrEmpty: Array&amp;lt;{ key: string, value: string }&amp;gt; = await stateClient.getAppStates({
  filter: "key = 'might-not-exist'",
  add-fields: "value",
});&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and build your logic based on empty/non-empty-array result.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Nov 2023 10:36:35 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/client-state-SDK-informations-about-error-being-thrown/m-p/218668#M416</guid>
      <dc:creator>gregor_riegler</dc:creator>
      <dc:date>2023-11-20T10:36:35Z</dc:date>
    </item>
    <item>
      <title>Re: client-state SDK: informations about error being thrown</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/client-state-SDK-informations-about-error-being-thrown/m-p/218705#M417</link>
      <description>&lt;P&gt;Indeed, this seems to be the way to go in my case, as it would not require specific error handling. Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: FYI, `isErrorResponseError` is exposed in the SDK itself, and it seemed like the way to go, but next time I will use the "simplified" condition or the solution you provided without the explicit error handling &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jul 2023 08:46:39 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/client-state-SDK-informations-about-error-being-thrown/m-p/218705#M417</guid>
      <dc:creator>david_petroni</dc:creator>
      <dc:date>2023-07-21T08:46:39Z</dc:date>
    </item>
  </channel>
</rss>

