# How do I make a bot stop playing a script if an error occurs?

> Loadster has an option to immediately stop playing a script if validation fails or some other error happens. Otherwise, the script can keep playing.

Source: https://loadster.com/faqs/stop-on-error/

There are different types of errors that can happen when you're playing a Loadster script.

**Socket errors** include anything that prevents a valid TCP connection from being made or maintained. This includes
connection timeouts, socket timeouts, and connections being closed prematurely.

**Protocol errors** such as HTTP 500, HTTP 401, etc mean that the server has received your request, but is declining
or unable to handle it.

**Validation errors** happen when one of your custom validators fails in Loadster. For example, you might have created
a validator to make sure the word "Welcome" occurs in the response body. If it isn't found, the validator will throw
an error.

## Default error handling behavior

Loadster's default behavior when an error is encountered is to report the error and continue playing the script.
This is desirable when errors are intermittent or outside your control, and where the requests are stateless and
the later steps in your script don't have any dependency on them.

However, the default behavior is undesirable for steps that the rest of your script depends on, such as a login step
or a step that creates a resource on the server that you'll reference later in the same script. In these situations
a single error can cascade to more errors after it, making it difficult to discover the root cause, so it's better to
stop that iteration of the script as soon as such an error occurs.

## Changing error handling behavior globally

To change Loadster's error handling behavior globally, go to <a href="https://loadster.com/dashboard/settings">Settings</a>
and check **Halt script execution on any error**. When this is checked, any error will cause the bot to stop their
current iteration of the script. If a load test is in progress, and time is remaining, the bot will then start
a brand new iteration of the script instead of continuing.

## Changing error handling behavior for an individual bot or script

Overriding the error handling behavior is sometimes necessary, for example, when you are testing an API and expect
an HTTP 4xx response. To override Loadster's error handling behavior for a single bot or script, you can call the following from a
[code block](https://loadster.com/manual/code-blocks/):

```javascript
bot.setHaltOnError(false); // Don't halt on errors
bot.setHaltOnError(true); // Do halt on errors
```



