I am sending a request with the “HTTP request” activity. With the help of the “Verify Expression” activity, I verify if the status code equals 200.
In case the status code equals 200, I get a short “verification has passed” message, which is desired. In case the status code does not equal 200, and only then, I would like to have the response body attached to the message for further analysis.
I found a solution here that suggests using the result output to further enhance the log based on the resulting boolean value. Unfortunately, The execution stops with the failed verification step, because “ContinueOnFailure = false” is set. So, the subsequent step is not going to be executed.
Is there another possibility to set a custom output based on the verification result?
A switch activity is more appropriate here since you only want to check the status code and not have different criteria for each block.
You can use 200 for the good response, add some other reponse codes you recognize and perhaps want to handle differently and use default for all the unknown codes.
per my view, “if activity” is better as requirement is to only check if not equal to 200… As you said, switch is more appropriate when we have requirement of verifying different status codes and need to provide respective response for each.
Yes, but a Switch statement can easily handle the 200 and put everything else in default for the initial requirement but is also very easy to scale for other response codes, which are common with an API call.
Its not better if you build your stuff to only handle the current requirement and don’t plan to easily extend functionality later, thats also why its a general coding principle to plan out your code this way. Swich makes alot more sense in this context.
Thank you, @Jon_Smith & @sonaliaggarwal47, for the quick responses.
How do I stop the execution (within a switch or if/ else statement) if the condition (status code == 200) is not satisfied? I could only find an appropriate property in the “Verify Expression” activity.
This might work. But I basically rebuilt the “Verify Expression” activity then when I implement it with an if/ else statement, write the necessary logs and throw an exception in case the status code does not equal 200.