agsh / onvif

ONVIF node.js implementation
http://agsh.github.io/onvif/
MIT License
693 stars 236 forks source link

Better SOAP error handling #141

Closed bl0ggy closed 4 years ago

bl0ggy commented 4 years ago

On SOAP error, some cameras send a wrong SOAP structure (see Issue #73). This PR permit to avoid having the error "TypeError: Cannot read property '0' of undefined", but instead will try to read both reason and detail information, if one of them is wrong, we can still get the other.

coveralls commented 4 years ago

Coverage Status

Coverage decreased (-0.4%) to 86.873% when pulling e57d9b2de7f47085938133257c51bf26e726af0f on bl0ggy:better_soap_error_handling into 2a7f9fe267058e8d069253f7d1189e5744b09470 on agsh:master.

RogerHardiman commented 4 years ago

Hi The try/catch is fine. In another part of the project (in some of the Pull event handler code) I import the lodash-get library (a small part of lodash). This has a _get fuction which does not throw if you get an item that is null (or the parent is null)

You can see me using it here... https://github.com/agsh/onvif/commit/ccdaff3a09b0232ebc4e9841ec74e8bdef5c2554

So I'll do the commit because try/catch is fine. But _get may give cleaner looking code in the future.

Thanks Roger

bl0ggy commented 4 years ago

I did not know about that library, thank you for the information.

RogerHardiman commented 4 years ago

There are a few NodeJS libraries that are very popular and used in lots of software. One is called Underscore and the other is called Lodash.

They are libraries packed will handy functions to make writing javascript easier.

Roger