VerifyExpression: Stop on Failure and log additional info

Hi there,

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?

Thanks!

Hi @Hieronymus_Bot,

You can also use if else activity.

if (statuscode = 200) then print message “verification has passed” else

Regards
Sonali

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.

@Jon_Smith,

Thank you for your suggestion!

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.

Regards
Sonali

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.

@Jon_Smith,

Scaling or coding principle point of view, I agree :slight_smile:

Appreciate your thoughts around same!!

Regards
Sonali

1 Like

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.

Hi @Hieronymus_Bot,

Sorry didn’t get you.

What does you mean by :how to stop the execution". Do you want to stop the execution of the workflow if status code is not 200?

Regards
Sonali

You can throw an exception? Depends on how much you want to stop?

Exactly. I am running a test case and doing some API calls for preparation. If one of them fails, then I want to stop execution immediately.

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.

1 Like

@Hieronymus_Bot,

Sounds right to me…

  1. check the status code
  2. if status code is other than 200, then log the messages you want to… Post which, throw an exception.

Regards
Sonali

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.