# Post-response Scripts Not Running when 502 Gateway Error is Encountered

**URL:** <https://community.postman.com/t/post-response-scripts-not-running-when-502-gateway-error-is-encountered/75451>\
**Category:** Help Hub\
**Tags:** collection-runner, newman-reports\
**Created:** [February 14, 2025, 10:07am UTC](https://community.postman.com/t/post-response-scripts-not-running-when-502-gateway-error-is-encountered/75451 "2025-02-14T10:07:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![maclazaro](https://avatars.discourse-cdn.com/v4/letter/m/7ba0ec/32.png) [@maclazaro](https://community.postman.com/u/maclazaro)\
**Post date:** [February 14, 2025, 10:07am UTC](https://community.postman.com/t/post-response-scripts-not-running-when-502-gateway-error-is-encountered/75451/1 "2025-02-14T10:07:48Z")

</div>

I have a test suite with a response status code validation.

One of my endpoints is throwing a 502 Gateway Error:

Postman:

 ![Screenshot 2025-02-14 175244](https://us1.discourse-cdn.com/getpostman/original/3X/2/9/29df392f5ca8b272331980123133b2d1927abb90.png)

Newman:

 ![Screenshot 2025-02-14 175143](https://us1.discourse-cdn.com/getpostman/original/3X/6/1/6171c18317bb6ba0362edfe2640382c22c9f76c9.png)

In my Newman report, my test validations are not failing:

 ![Screenshot 2025-02-14 175508](https://us1.discourse-cdn.com/getpostman/original/3X/a/4/a481d845336de3132802ef32bfcfab3da3132ab8.png)

But it’s showing under the Failed Tests tab:

 ![Screenshot 2025-02-14 180551](https://us1.discourse-cdn.com/getpostman/original/3X/f/0/f090b535d111ebe947bee997e8df7af3a8ed7543.png)

I even added the following but it’s showing the same results as above:

```auto
pm.test("JSON response validation", function() {    
    pm.expect(jsonData).to.be.an('object');
});

```

How can I force the non-200 (502) assertion failure to show up? It’s misleading that it’s showing as green.

---

<div class="post-metadata">

**Author:** ![gbadebo-bello](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/gbadebo-bello/32/12175_2.png) [@gbadebo-bello](https://community.postman.com/u/gbadebo-bello)\
**Post date:** [February 14, 2025, 2:23pm UTC](https://community.postman.com/t/post-response-scripts-not-running-when-502-gateway-error-is-encountered/75451/2 "2025-02-14T14:23:24Z")

</div>

Hi @maclazaro. Welcome to the Postman Communtiy :postman_logo:.

The response body from the screenshots you shared is an HTML body and the test assertion you wrote only validates the response body and not the response code. To validate the response code of the request, add the test script:

```auto
pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
});

```

---

<div class="post-metadata">

**Author:** ![maclazaro](https://avatars.discourse-cdn.com/v4/letter/m/7ba0ec/32.png) [@maclazaro](https://community.postman.com/u/maclazaro)\
**Post date:** [February 15, 2025, 2:22am UTC](https://community.postman.com/t/post-response-scripts-not-running-when-502-gateway-error-is-encountered/75451/3 "2025-02-15T02:22:58Z")

</div>

Forgot to mention I already have the status code validation, though slightly different from yours:

```auto
pm.test("Success", function () {
    pm.expect(pm.response.code).to.be.equal(200);
});

```

I added yours to my SCN-027 but got the same results:

 ![Screenshot 2025-02-15 100708](https://us1.discourse-cdn.com/getpostman/original/3X/a/a/aa7244c8b8d1165a27256b9bcc6f161d429d3001.png)

 ![Screenshot 2025-02-15 101304](https://us1.discourse-cdn.com/getpostman/original/3X/4/7/47db9005b0d56d67b29ac4fd57495c7baa39944c.png)
