<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Abhishek Johri</title>
    <description>The latest articles on DEV Community by Abhishek Johri (@requestfox).</description>
    <link>https://dev.to/requestfox</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4261165%2Ffdeeaea8-df94-4414-97a5-f7272f594cbb.png</url>
      <title>DEV Community: Abhishek Johri</title>
      <link>https://dev.to/requestfox</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/requestfox"/>
    <language>en</language>
    <item>
      <title>How to catch API errors hidden inside a 200 OK</title>
      <dc:creator>Abhishek Johri</dc:creator>
      <pubDate>Mon, 23 Nov 2026 18:36:28 +0000</pubDate>
      <link>https://dev.to/requestfox/how-i-catch-api-errors-hidden-inside-a-200-ok-3mfp</link>
      <guid>https://dev.to/requestfox/how-i-catch-api-errors-hidden-inside-a-200-ok-3mfp</guid>
      <description>&lt;p&gt;A green 200 in the Network tab feels like good news. The request went out, the server answered, and nothing turned red. But a lot of APIs answer "200 OK" even when the thing you asked for didn't happen. The real answer is inside the response body, and if you only look at the status code, you never see it.&lt;/p&gt;

&lt;p&gt;This kind of bug is sneaky because nothing looks broken. The page loads and there's no error message. You just get an empty list, a total of zero, or a button that seems to do nothing.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it looks like
&lt;/h2&gt;

&lt;p&gt;Here's a typical REST response that comes back with status 200:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"success"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"error"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"code"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"CART_LOCKED"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Cart is being updated, try again"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And here's the GraphQL version. Many GraphQL servers return 200 even when part of the query fails, and put the problem in an &lt;code&gt;errors&lt;/code&gt; array:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"data"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"cart"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"errors"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Not authorised to read cart"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"path"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"cart"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In both cases the status code says everything is fine. The body says it isn't.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why it's so easy to miss
&lt;/h2&gt;

&lt;p&gt;Most of our tools are built around the status code. DevTools shows a request in red when the status is 4xx or 5xx, so a 200 with an error inside looks exactly like a healthy call.&lt;/p&gt;

&lt;p&gt;Many tests do the same thing. &lt;code&gt;response.ok&lt;/code&gt; is true for any status from 200 to 299, so a test that only checks it will pass.&lt;/p&gt;

&lt;p&gt;The UI often hides it too. A front end that expects &lt;code&gt;data.items&lt;/code&gt; and gets &lt;code&gt;null&lt;/code&gt; usually falls back to an empty state, which reads as "no results" instead of "something broke".&lt;/p&gt;

&lt;h2&gt;
  
  
  How to find it in Chrome DevTools
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Open DevTools (F12) and go to the &lt;strong&gt;Network&lt;/strong&gt; tab.&lt;/li&gt;
&lt;li&gt;Tick &lt;strong&gt;Preserve log&lt;/strong&gt;, so the list survives a reload.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Fetch/XHR&lt;/strong&gt; to hide images, scripts and styles.&lt;/li&gt;
&lt;li&gt;Do the thing that looked wrong on the page.&lt;/li&gt;
&lt;li&gt;Click each call and open the &lt;strong&gt;Response&lt;/strong&gt; or &lt;strong&gt;Preview&lt;/strong&gt; tab.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That works, but checking calls one by one gets slow on a busy page. Two shortcuts help:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Press &lt;strong&gt;Ctrl+F&lt;/strong&gt; (Cmd+F on a Mac) while the Network panel is open. It searches across the requests, response bodies included, so you can search for &lt;code&gt;errors&lt;/code&gt; or &lt;code&gt;success&lt;/code&gt; and jump straight to the call.&lt;/li&gt;
&lt;li&gt;Type &lt;code&gt;status-code:200&lt;/code&gt; in the filter box to see only the calls that "succeeded", then go through just those.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Catch it in your tests too
&lt;/h2&gt;

&lt;p&gt;If you use Playwright, don't stop at the status code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;responsePromise&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;waitForResponse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'**/api/cart'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getByRole&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'button'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Add to cart'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;click&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;responsePromise&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toBe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;success&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="ow"&gt;not&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toBe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;errors&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toBeUndefined&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  A short checklist
&lt;/h2&gt;

&lt;p&gt;Before you call a screen "working", check these in its responses:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Does the body have &lt;code&gt;errors&lt;/code&gt;, &lt;code&gt;error&lt;/code&gt; or &lt;code&gt;"success": false&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;Is &lt;code&gt;data&lt;/code&gt; null or empty when the screen should show something?&lt;/li&gt;
&lt;li&gt;Does what the screen shows match what the API sent?&lt;/li&gt;
&lt;li&gt;While you're there: was the call slow, or did it fire twice?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A 200 only tells you the server answered. It doesn't tell you it said yes. Read the body.&lt;/p&gt;

&lt;p&gt;How does your team catch these? I'd like to hear other tricks.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This article was written with the help of AI and checked by me.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>testing</category>
      <category>api</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
