# Can we test/assert for ECONNRESET?

**URL:** <https://community.postman.com/t/can-we-test-assert-for-econnreset/25212>\
**Category:** Help Hub\
**Tags:** tests\
**Created:** [June 25, 2021, 4:08pm UTC](https://community.postman.com/t/can-we-test-assert-for-econnreset/25212 "2021-06-25T16:08:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![spn2016](https://avatars.discourse-cdn.com/v4/letter/s/ac8455/32.png) [@spn2016](https://community.postman.com/u/spn2016)\
**Post date:** [June 25, 2021, 4:08pm UTC](https://community.postman.com/t/can-we-test-assert-for-econnreset/25212/1 "2021-06-25T16:08:45Z")

</div>

_My question_: A service we are testing should not accept requests with TLS 1.0 or 1.1 and it behaves correctly denying those connections.

When send a request via postman and force it to use TLS 1.0 (or TLS1.1), what’s returned by postman is

 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/3/348dbd9444e2540f0350f3016a7cd768e70bf04b.png)

Console shows: Error: read ECONNRESET  
is there an way to detect & test for this as the expected? so the test would pass.

---

<div class="post-metadata">

**Author:** ![kevin.swiber](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/kevin.swiber/32/3820_2.png) [@kevin.swiber](https://community.postman.com/u/kevin.swiber)\
**Post date:** [June 25, 2021, 4:30pm UTC](https://community.postman.com/t/can-we-test-assert-for-econnreset/25212/2 "2021-06-25T16:30:45Z")

</div>

Hey @spn2016,

You’ll have to do a workaround here. Postman will not execute tests if it can’t get a network response from the URL.

One workaround is to actually send the request in a `pm.sendRequest()` call in a pre-request script. Then you can check for an `ECONNRESET` error and set a variable with the result. This is essentially moving the test execution to the pre-request script. We still want the assertion in the Tests section of the request, which is why we’re setting a variable with the result. We can assert on that result in the Tests section.

Example below.

pre-request script:

```auto
// Store the original URL.
const subjectURL = pm.request.url.toString();

// Set the URL to one that will execute successfully.
pm.request.url = 'https://postman-echo.com/delay/0';

// Set up a variable that we'll test in the Tests section.
const variableName = `does${pm.info.requestId}Fail`;
pm.variables.set(variableName, false);

// Set request options.
const options = {
  method: pm.request.method,
  url: subjectURL
};

// Send the request using pm.sendRequest().
pm.sendRequest(options, (err, _res) => {
  // if the request fails, update our variable to true (success).
  if (err && err.errno == 'ECONNREFUSED') {
    pm.variables.set(variableName, true);
  }
});

```

test script:

```auto
pm.test('does request fail on TLS 1.0', () => {
  // fetch the variable set in the pre-rquest script.
  const variableName = `does${pm.info.requestId}Fail`;
  const subject = pm.variables.get(variableName);

  // assert that the request failed with ECONNRESET.
  pm.expect(subject).to.be.true;
});

Hope that helps!

```

---

<div class="post-metadata">

**Author:** ![navigation-astronom4](https://avatars.discourse-cdn.com/v4/letter/n/ba8739/32.png) [@navigation-astronom4](https://community.postman.com/u/navigation-astronom4)\
**Post date:** [August 20, 2022, 10:11pm UTC](https://community.postman.com/t/can-we-test-assert-for-econnreset/25212/3 "2022-08-20T22:11:27Z")

</div>

This is a great answer, thank you Kevin.
