agsh / onvif

ONVIF node.js implementation
https://onvif.pages.dev
MIT License
703 stars 240 forks source link

TypeError in parseSOAPString on SOAP Error: "TypeError: Cannot read property '0' of undefined" #73

Closed dmm closed 4 years ago

dmm commented 7 years ago

The parseSOAPString function in utils.js is crashing with this error:

TypeError: Cannot read property '0' of undefined
at utils.js:89:64

The problem is that your code is expecting a "text" object in "detail" (result.envelope.body[0].fault[0].detail[0].text[0]) but the message from the camera has none.

To get this far I also had to work around issue #66 . Let me know if I can provide any more details

Thanks!

Here's the SOAP message:

{
  "envelope": {
    "header": [
      ""
    ],
    "body": [
      {
        "fault": [
          {
            "code": [
              {
                "value": [
                  "SOAP-ENV:Receiver"
                ],
                "subcode": [
                  {
                    "value": [
                      "Ter:PTZNotSupported"
                    ],
                    "subcode": [
                      ""
                    ]
                  }
                ]
              }
            ],
            "reason": [
              {
                "text": [
                  {
                    "_": "PTZ not supported",
                    "$": {
                      "xml:lang": "en"
                    }
                  }
                ]
              }
            ],
            "node": [
              "http://www.w3.org/2003/05/soap-envelope/node/ultimateReceiver"
            ],
            "role": [
              "http://www.w3.org/2003/05/soap-envelope/node/ultimateReceiver"
            ],
            "detail": [
              "PTZ is not supported by the device."
            ]
          }
        ]
      }
    ]
  }
}
hawkeye64 commented 6 years ago

If you're still interested in this, I have put a PR in that handles this. Not all cameras respond the same way, so I can only hope that it resolves your issue. For me, Axis and Hikvision were fine, but I was getting something similar for Pelco.

Cannot read property '0' of undefined fixes

chriswiggins commented 4 years ago

Closing out old issue