# API error status code with fetch's POST method

**URL:** <https://forums.creativeclouddeveloper.com/t/api-error-status-code-with-fetchs-post-method/1358>\
**Category:** UXP Plugin API\
**Tags:** feature-request, javascript\
**Created:** [October 23, 2019, 2:39pm UTC](https://forums.creativeclouddeveloper.com/t/api-error-status-code-with-fetchs-post-method/1358 "2019-10-23T14:39:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmraptis](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/dmraptis/32/655_2.png) [@dmraptis](https://forums.creativeclouddeveloper.com/u/dmraptis)\
**Post date:** [October 23, 2019, 2:39pm UTC](https://forums.creativeclouddeveloper.com/t/api-error-status-code-with-fetchs-post-method/1358/1 "2019-10-23T14:39:35Z")

</div>

I use fetch API to fetch data from our server with the POST method.

It seems that fetch API throws a " Network request failed" error every time the status code is 4XX. However, I need these codes in order to show the appropriate message to our users. Otherwise, the UX flow of our plugin could end confusing.

Btw, the GET method gives me the correct error codes.

Is there a way to access the exact status code of the error?

---

<div class="post-metadata">

**Author:** ![cpryland](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/cpryland/32/1172_2.png) [@cpryland](https://forums.creativeclouddeveloper.com/u/cpryland)\
**Post date:** [October 23, 2019, 2:57pm UTC](https://forums.creativeclouddeveloper.com/t/api-error-status-code-with-fetchs-post-method/1358/2 "2019-10-23T14:57:16Z")

</div>

Welcome to the forum!

I don’t mean to be cheeky, but aren’t you abusing data fetching by using POST instead of GET? Or are you actually changing something?

---

<div class="post-metadata">

**Author:** ![dmraptis](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/dmraptis/32/655_2.png) [@dmraptis](https://forums.creativeclouddeveloper.com/u/dmraptis)\
**Post date:** [October 24, 2019, 7:56am UTC](https://forums.creativeclouddeveloper.com/t/api-error-status-code-with-fetchs-post-method/1358/3 "2019-10-24T07:56:51Z")

</div>

Thank you! I’m glad to be part of this community!

Sorry for not clarifying this point. I use POST to send a Base64 image to the server and I want to get back the transformed image or the error status code in case of an error.

---

<div class="post-metadata">

**Author:** ![pklaschka](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/pklaschka/32/3162_2.png) [@pklaschka](https://forums.creativeclouddeveloper.com/u/pklaschka)\
**Post date:** [October 24, 2019, 8:25am UTC](https://forums.creativeclouddeveloper.com/t/api-error-status-code-with-fetchs-post-method/1358/4 "2019-10-24T08:25:30Z")

</div>

Hi @dmraptis (also from me: Welcome to the forum 👋🙂)

According to [Network APIs · Adobe XD Plugin Reference](https://adobexdplatform.com/plugin-docs/reference/uxp/network-index.html#fetch-support), XD’s `fetch` implementation uses [GitHub - JakeChampion/fetch: A window.fetch JavaScript polyfill.](https://github.com/github/fetch) as a sort of Polyfill on top of XHR to provide the `fetch` function. In the documentation of said library (more specifically: the README), it says that error codes have to manually get filtered (cf. [GitHub - JakeChampion/fetch: A window.fetch JavaScript polyfill.](https://github.com/github/fetch#handling-http-error-statuses)), which, apperently, XD’s implementation does. Since this, then, appears to be an undocumented kind of error (there is no specification of such an error in the XD docs, meaning `fetch` shouldn’t actually reject in case of a 4XX or 5XX response).

If there is no `status` property in the `Response` (according to MDN, it actually shouldn’t reject even if there is a status code other than 2XX), as specified in the [MDN docs](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API), this is undocumented and your safest bet therefore would probably be to, for now, use an [XMLHttpRequest](https://adobexdplatform.com/plugin-docs/reference/uxp/class/XMLHttpRequest.html)…

---

<div class="post-metadata">

**Author:** ![dmraptis](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/dmraptis/32/655_2.png) [@dmraptis](https://forums.creativeclouddeveloper.com/u/dmraptis)\
**Post date:** [October 30, 2019, 2:58pm UTC](https://forums.creativeclouddeveloper.com/t/api-error-status-code-with-fetchs-post-method/1358/5 "2019-10-30T14:58:51Z")

</div>

Thank you a lot for your extensive response! I’ll use an [XMLHttpRequest](https://adobexdplatform.com/plugin-docs/reference/uxp/class/XMLHttpRequest.html) for now.
