# Successful Synthetics Test if Error is Received

**URL:** <https://discuss.elastic.co/t/successful-synthetics-test-if-error-is-received/362966>\
**Category:** Synthetics\
**Created:** [July 11, 2024, 3:06pm UTC](https://discuss.elastic.co/t/successful-synthetics-test-if-error-is-received/362966 "2024-07-11T15:06:22Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![DougR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dougr/32/48095_2.png) [@DougR](https://discuss.elastic.co/u/DougR)\
**Post date:** [July 11, 2024, 3:06pm UTC](https://discuss.elastic.co/t/successful-synthetics-test-if-error-is-received/362966/1 "2024-07-11T15:06:22Z")

</div>

I have a need to run a lightweight test on a specific subnet to validate that it is isolated from our internal network; in other words, the the test is SUCCESSFUL if a DNS error or a timeout is received.

I have created the test and validated that the monitor fails as expected. My question is, is there a way that I can set the test to SUCCESSFUL on a DNS error or timeout and UNSUCCESSFUL under any other conditions (e.g., if any HTTP code is received back, even a 4xx or 5xx, it indicates that the test is communicating with the server and should therefore be a failure).

Can this be done and, if so, how?

---

<div class="post-metadata">

**Author:** ![carly.richmond](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carly.richmond/32/104935_2.png) [@carly.richmond](https://discuss.elastic.co/u/carly.richmond)\
**Post date:** [July 11, 2024, 7:24pm UTC](https://discuss.elastic.co/t/successful-synthetics-test-if-error-is-received/362966/2 "2024-07-11T19:24:00Z")

</div>

Hi @DougR,

Are you using a lightweight YAML-based monitor or a scripted browser based monitor written with Playwright?

It's not something I've done myself, but I wonder if wrapping the appropriate call in a try/catch to catch the [timeout error](https://playwright.dev/docs/api/class-timeouterror) and assert true in Playwright would work? Have you tried that?

---

<div class="post-metadata">

**Author:** ![DougR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dougr/32/48095_2.png) [@DougR](https://discuss.elastic.co/u/DougR)\
**Post date:** [July 15, 2024, 4:20pm UTC](https://discuss.elastic.co/t/successful-synthetics-test-if-error-is-received/362966/3 "2024-07-15T16:20:46Z")

</div>

I'm using a lightweight test. I didn't think about creating a journey and using a try/except.

---

<div class="post-metadata">

**Author:** ![carly.richmond](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carly.richmond/32/104935_2.png) [@carly.richmond](https://discuss.elastic.co/u/carly.richmond)\
**Post date:** [July 16, 2024, 9:19am UTC](https://discuss.elastic.co/t/successful-synthetics-test-if-error-is-received/362966/4 "2024-07-16T09:19:09Z")

</div>

Thanks for confirming. For the lightweight monitor have you tried adding the 4xx and 5xx response codes to the _Response checks_ option under _Advanced options_:

 ![Screenshot 2024-07-16 at 10.14.36](https://us1.discourse-cdn.com/elastic/original/3X/0/d/0d720720d1f04e483569682e20092bdcd963b192.png)

I have tried a test overriding the codes with 4xx codes and it does seem to change the failure to a passing test:

 ![Screenshot 2024-07-16 at 10.17.28](https://us1.discourse-cdn.com/elastic/original/3X/7/a/7ac29ac5a5c41a7b8ef16c8ab08830d2f9f1bba5.jpeg)

You are absolutely right that by default 4xx and 5xx response codes are treated as a failure, but you can override the codes here.

Let me know if that solves your issue.

---

<div class="post-metadata">

**Author:** ![DougR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dougr/32/48095_2.png) [@DougR](https://discuss.elastic.co/u/DougR)\
**Post date:** [July 16, 2024, 12:57pm UTC](https://discuss.elastic.co/t/successful-synthetics-test-if-error-is-received/362966/5 "2024-07-16T12:57:48Z")

</div>

Thanks - I thought of that as well, but it won't work for this use case.

In my use case, a DNS failure or a timeout indicate that the test is running as expected. The network I'm testing is an external-facing network that should be totally isolated from our internal network; there should be no route to the internal network and it should not be able to perform a DNS lookup for a host on our internal network. If it returns an HTTP code, that means that the monitor is able to reach the internal server and the network is not isolated, so the test has failed.

If there's not an easy way to do this with a lightweight test, then my best bet is probably to use a journey with a try/except block as you suggested earlier.

Thx!

---

<div class="post-metadata">

**Author:** ![shahzad31](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shahzad31/32/51637_2.png) [@shahzad31](https://discuss.elastic.co/u/shahzad31)\
**Post date:** [July 16, 2024, 1:14pm UTC](https://discuss.elastic.co/t/successful-synthetics-test-if-error-is-received/362966/6 "2024-07-16T13:14:37Z")

</div>

@DougR if i understand correctly, what you are saying is we should consider the error as a success essentially, some sort of `negate: true` option in monitor configuration. Where if monitor is down, we should consider it as up, we have even internally have had this kind of use- case, where essentially we are monitoring access to assets, and all those monitors appears down in UI. But our SRE team has been living with that 🙂

i think it can be a nice enhancement request.

---

<div class="post-metadata">

**Author:** ![DougR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dougr/32/48095_2.png) [@DougR](https://discuss.elastic.co/u/DougR)\
**Post date:** [July 16, 2024, 2:25pm UTC](https://discuss.elastic.co/t/successful-synthetics-test-if-error-is-received/362966/7 "2024-07-16T14:25:49Z")

</div>

@shahzad31 - That is exactly what I'm trying to accomplish, and you're right, that would be an awesome enhancement. Where does an enhancement request get submitted for a lightweight monitor? Just into the synthetics repo, or elsewhere?

Thx!

---

<div class="post-metadata">

**Author:** ![shahzad31](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shahzad31/32/51637_2.png) [@shahzad31](https://discuss.elastic.co/u/shahzad31)\
**Post date:** [July 16, 2024, 3:10pm UTC](https://discuss.elastic.co/t/successful-synthetics-test-if-error-is-received/362966/8 "2024-07-16T15:10:12Z")

</div>

@DougR it will technically go into beats repo [GitHub - elastic/beats: 🐠 Beats - Lightweight shippers for Elasticsearch & Logstash](https://github.com/elastic/beats)
