Search code examples
javascriptpostmanpostman-pre-request-script

Throw error message in pre request script is not working


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


Solution

  • 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