Handle empty response

I am using sendRequest function to verify if there are any data in the API or not.
If there is some data then I will proceed and execute my logic.
Sometimes there will be empty response as well. just like below

Since the response is empty, I should not execute my logic, but everytime the logic is being executed,
Any idea how I can stop going to else condition

	pm.sendRequest(createGetTariffsRequest(), (error, response) => {
		if (error) {
			console.error(error);
		} else {
			if (response!= null) {
           logic to create new data
           }

image

What status code is being returned when it has an empty response. Hopefully it will be a 204 - no content, which you should be able to use in your IF statement.

Unfortunately in both cases the response code is 200.
When there is data and without data , response code is 200.
So I can’t use this in the IF condition.
I am looking for some condition based on the body in the response

If you console log the response, does it give you anything?

If you try and parse it, does it error or return a blank object {}

Below is the response from the console.
Only difference is in the stream data.
I am thinking how to use this in the if condition

It looks like stream.data = 0 when its empty.

So perhaps have a check for the status code, and combine it with a check for response.stream.data != 0

Hi,

I did like this
if (response.stream != 0) {
//code here
}