mclarkk/lifxlan

Please implement Exceptions for better Error handling

henryruhs opened this issue · 0 comments

Hello,

it would be nice to have some exceptions to be thrown:

  1. Discovery failed while using LifxLAN() so throw LifxConnectionException
  2. Socket that don't respond should throw LifxTimeoutException

Hacky solution that includes general WorkflowException to test connection:

def api_factory():
	api = None

	try:
		from lifxlan import LifxLAN, WorkflowException

		try:
			api = LifxLAN()
		except WorkflowException:
			exit(wording.get('connection_no').format('LIFX LIGHT') + wording.get('exclamation_mark'))
		return api
	except ImportError:
		exit(wording.get('package_no').format('LIFXLAN') + wording.get('exclamation_mark'))

Wanted solution that throws LifxConnectionException and LifxTimeoutException:

def api_factory():
	api = None

	try:
		from lifxlan import LifxLAN, LifxConnectionException, LifxTimeoutException

		try:
			api = LifxLAN()
		except (LifxConnectionException, LifxTimeoutException):
			exit(wording.get('connection_no').format('LIFX LIGHT') + wording.get('exclamation_mark'))
		return api
	except ImportError:
		exit(wording.get('package_no').format('LIFXLAN') + wording.get('exclamation_mark'))