# How to stop all request in Collection Runner on any error?

**URL:** <https://community.postman.com/t/how-to-stop-all-request-in-collection-runner-on-any-error/15923>\
**Category:** Help Hub\
**Tags:** collections\
**Created:** [September 16, 2020, 11:56am UTC](https://community.postman.com/t/how-to-stop-all-request-in-collection-runner-on-any-error/15923 "2020-09-16T11:56:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dracorp](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/dracorp/32/5535_2.png) [@dracorp](https://community.postman.com/u/dracorp)\
**Post date:** [September 16, 2020, 11:56am UTC](https://community.postman.com/t/how-to-stop-all-request-in-collection-runner-on-any-error/15923/1 "2020-09-16T11:56:33Z")

</div>

Hello  
In **Pre-request Script** tab I set a few variables, based on the REST API answers (_pm.sendRequest()_).  
For some situation the error is returned, so I cannot continue next iterations.  
How can I stop all future steps, whole Collection Runner? On **Tests** tab I’ve tried set **postman.setNextRequest(null)** but it does not work. Can I do this from **Pre-request Script**?  
This [How to stop Collection Runner on error?](https://community.postman.com/t/how-to-stop-collection-runner-on-error/12647/10) does not work for me.

Kind regards

---

<div class="post-metadata">

**Author:** ![kclausing](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/kclausing/32/5133_2.png) [@kclausing](https://community.postman.com/u/kclausing)\
**Post date:** [September 16, 2020, 12:38pm UTC](https://community.postman.com/t/how-to-stop-all-request-in-collection-runner-on-any-error/15923/2 "2020-09-16T12:38:52Z")

</div>

@dracorp without your code as an example, it is hard to say why it did not work.

But notice in the example from the post you reference, the steps are contained within the same pm.test node. The node will perform everything in sequence, and it will only set the postman.setNextRequest(); after a successful 200 status. If 200 status fails, then the next request is still null and it stops.

Based on what you mention, does your ( _pm.sendRequest()_ ) node contain the setting of the variables after success? or are those contained in a separate request node?

(It is also possible that this requires a certain version if postman?? I am on version 7.32.0

pm.test(“Status code is 200”, function () {  
postman.setNextRequest(null);  
pm.response.to.have.status(200);  
postman.setNextRequest();  
//convert to json format  
var RespData = xml2Json(responseBody);  
//set environment level variable  
pm.environment.set(“PolicyNumber”, RespData[‘OnlineData.autoSaveDataRs’][’$’][‘policyNumber’]);  
//return policy number in test tab  
pm.test(pm.environment.get(“PolicyNumber”));  
});

---

<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:** [September 16, 2020, 7:26pm UTC](https://community.postman.com/t/how-to-stop-all-request-in-collection-runner-on-any-error/15923/3 "2020-09-16T19:26:38Z")

</div>

Hi @dracorp,

To stop the execution, you can throw an error in your pre-request script.

```auto
throw new Error('halt');

```

That should stop execution of the request and the collection run.

Best,

Kevin

---

<div class="post-metadata">

**Author:** ![dracorp](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/dracorp/32/5535_2.png) [@dracorp](https://community.postman.com/u/dracorp)\
**Post date:** [September 17, 2020, 11:47am UTC](https://community.postman.com/t/how-to-stop-all-request-in-collection-runner-on-any-error/15923/4 "2020-09-17T11:47:48Z")

</div>

Hi @kclausing and @kevin.swiber  
It, throw new Error, stops Pre-request Script but not the whole collection. Tests are omitted.  
This is good but not enough.

> Not great, not terrible

---

<div class="post-metadata">

**Author:** ![kawsar-ahmed](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@kawsar-ahmed](https://community.postman.com/u/kawsar-ahmed)\
**Post date:** [June 13, 2022, 6:50am UTC](https://community.postman.com/t/how-to-stop-all-request-in-collection-runner-on-any-error/15923/5 "2022-06-13T06:50:49Z")

</div>

This does not stop the next steps of collection.
