The script error

How can avoid followin error ?
throw new Error('The script type needs to be PayToPublicKeyHash or PayToScri
Error: The script type needs to be PayToPublicKeyHash or PayToScriptHash

The error states what the problem is. You’re trying to get an address from a script that is not PayToPublicKeyHash or PayToScriptHash. Only PayToPublicKeyHash or PayToScriptHash scripts can be transformed to addresses

following code is solve that problem ?
peer.on(‘tx’, function (tx) {
var transaction = tx.transaction;
transaction.inputs.forEach(function (inputs) {

                   if(inputs.script.isPublicKeyHashIn() || inputs.script.isScriptHashIn()){
                       var address = inputs.script.toString()


               txStaticInfo['inputs'] = intputAddresses;