Postman method to run in case on failure

Few automation framework comes with pre-defined methods which will run some code in case of failures. I am wondering if Postman has any such methods ?

My goal is to log a request and response in case of any failure.

How i achieve it now -

I have added a function with console.log for request and response in the pre-request script at the top of collections.
I have an if/else condition in tests. If the condition is satisfied then I add a pm.test(…) otherwise in else part(i.e. in case of failure) i call the method(which logs the request and response)

What i want instead is

It would have been nice if i can get rid of the if/else part and simply use a pre-defined something method like -

`Run on Failure console.log("Request: " + JSON.stringify(request))

Run on Failure"Response: " + responseBody)`

Hey @vikas543 :wave:

This isn’t something you can do at the collection level for now, using if/else is the right way to do it.