0
pm.sendRequest(options, function (err, res) {
    if (res.code == 400) {
        throw new Error("Invalid");
    }else{
        pm.request.headers.add({
        key: "Authorization",
        value: 'Bearer '+res.json().access_token});
    }
});

Above Pre Request Script is throwing Error

Response: There was an error in evaluating the Pre-request Script:Error: Invalid

Postman Version: 9.7.1, OS: Windows, App Type: Postman Desktop Application

Chand
  • 51
  • 7

1 Answers1

2

it does what it was asked , it throws the error “invalid” as the status was 400 .

so you get the mentioned error. saying “invalid” . Try changing the error message

PDHide
  • 18,113
  • 2
  • 31
  • 46
  • How to ignore "Response: There was an error in evaluating the Pre-request Script:" in the Error Response. I need to print only `Error: Invalid`. – Chand Dec 31 '21 at 08:21
  • @Chand what you mean by ignore , what are you trying to do with that throw error statement. – PDHide Dec 31 '21 at 10:05
  • if pre request script is failed, then with throw error statement I am stopping to send Main Request. – Chand Dec 31 '21 at 12:26