0

respons is coming back empty [] for this.rxInfos but below if condtion never executed any idea what is missing here ?

main.js

if (!Array.isArray(this.rxInfos) && this.rxInfos.length === 0) {
            return this.errorHandler(request, 'no rx found in the cache');
        }
7
  • Using &&, you are checking that both are true at the same time. Commented Jan 4, 2019 at 17:19
  • An empty array is still an array Commented Jan 4, 2019 at 17:19
  • @bugs The OP is checking if it is NOT an array Commented Jan 4, 2019 at 17:20
  • Use || instead of &&. Commented Jan 4, 2019 at 17:20
  • read it out loud: if (not an Array AND the length is zero) Commented Jan 4, 2019 at 17:21

2 Answers 2

2

You could check not an array or if no length.

The first part

!Array.isArray(this.rxInfos)

is true, if the value of this.rxInfos is not an array.

The logical OR || allows to end the check, which is important, if the first operand it truthy. If not, then an array is given and the second part

!this.rxInfos.length

with the length and their logical NOT ! is evaluated and that means, if a length of zero, the last part is true or if the length has another value than zero, the part yields false.

if (!Array.isArray(this.rxInfos) || !this.rxInfos.length) {
    return this.errorHandler(request, 'no rx found in the cache');
}
Sign up to request clarification or add additional context in comments.

1 Comment

The solution was to use || not &&, you made the change but didnt really explain why you made the change. Your length check and theirs accomplish the same thing so it is really inconsequential.
0

Just remove first !

 if (this.rxInfos !== undefined && Array.isArray(this.rxInfos) && this.rxInfos.length === 0) { return this.errorHandler(request, 'no rx found in the cache'); }

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.