Disable AssertionError when received status code 201

I’m getting the below error when receiving a 201 response code from a successful post.

Status code is 200 | AssertionError: expected response to have status code 200 but got 201

Is there a way to supress this, as the request has been successful?

Hey @jazzycow ,

Welcome to the community :wave:

Are you getting this error from one of your tests, if so, can you share more detailed information so that we can help you change it?
Or you can use this way,

 pm.test("Successful POST request", function () {
 pm.expect(pm.response.code).to.be.oneOf([200,201]);
 });

For example the screenshot and test block where you get this error.

Another method that could be used to pass anything that returns a 2XX code is this:

pm.response.to.be.success

The way that @yusuftaymann described is great if you want to limit that range to be specific codes. :trophy:

1 Like

OH, appologies for this. I had a folder defined with a test, that checked for status code of 200, not 201.

Luckly I posted this on the ‘noobs’ category :slight_smile:

I’ve completely forgotten that I’ve defined that there and when you get into inheritance you get cofused quickly.

Thanks for the prompt response.

1 Like

Thanks for the tip. I’ve used it now.

1 Like

I tried: pm.response.to.be.success, but I still got the following error:
Methed:GET Status code is 200 | AssertionError: expected response to have status code 200 but got 202

Hey @albushuang

You might need to extend the information about your particular issue a little more.

What’s the full piece of test code that you have?

In the context of the code that I posted in the thread:

This test would pass if the response code in in the 2XX range:

pm.test("Status code to be in the 2XX range", () => {
    pm.response.to.be.success
});

It would be a catch all for all the 2XX range of status codes but if you needed to test for specific codes, you would use:

pm.expect(pm.response.code).to.be.oneOf([200,201,400, 500]);