If else block in postman

else block is not getting executed

const invalidinput = pm.response.json();
const successfulorder=pm.response.json();
if(pm.response.to.have.status(400)){
pm.test(“validation of when input body is empty or invalid”, function(){
console.log(invalidinput);
pm.expect(invalidinput.error).to.eql(“Invalid or missing bookId.”);
})
}
else{
pm.test(“validation of json response for successfulorder”, function(){
pm.response.to.have.status(201);
pm.expect(successfulorder.created).to.eql(true);
})
}

for order post request , if the input body is not correct status will be 400, else the input body is correct and status is 200.
but when i am trying to execute with correct input body, the else block is not getting executed.
Please help me how to resolve this

Hi @akhilesh-ch

Try;

if(pm.response.status === 400){

Instead of;

if(pm.response.to.have.status(400)){