mallardduck / php-whois-client

A very basic Whois client for PHP. The library limits function to be a low-level client that handles only request and raw output.
GNU General Public License v3.0
16 stars 3 forks source link

error handling #14

Closed erichuang2015 closed 6 years ago

erichuang2015 commented 6 years ago

Hello

It is better to have error handling method for use in this script such as

try

catch

mallardduck commented 6 years ago

Generally you shouldn't need to use try/catch with this library. The library will only ever throw 2 types of exceptions and those generally happen due to user error; i.e. providing no input, providing a domain with a non-existent TLD, or inputting a domain with a TLD not on the lists used here.

The other type of exception to look out for are those thrown by libraries this one relies on. Luckily the only one of those I've seen are from the league/uri and usually that's related to a local, server, or project specific issue.

All that said, I think that when building on top of libraries it's always smart to use try/catch when you have a reason for it. In your case if the issue is still related to the public_suffix_list.dat used by the URI package then it may not matter either way. Not being able to reach that file will cause the URI parser to fail.

If this is indeed the case then I would suggest that you either give SimpleClient a try or extend AbstractWhoisClient yourself. If you use SimpleClient then you loose the Punnycode, URI parsing, and Whois Server Lookup - it's just a basic PHP whois client. You give it a whois server and a domain it will make a request and return results.

If you still want Punnycode and Whois Server Lookup then you can extend AbstractWhoisClient to build an implementation that excludes the League URI parser. Essentially you could reimplement Client as it is and just provide your own getSearchableHostname method using other means to resolve the Registrable domain.

mallardduck commented 6 years ago

Hey, I'm going to set this to closed since I think my reply answered your question. 😄