
Handling errors
===============

pyavdesk ships with three exception classes (``AVDeskError``, ``AVDeskLibraryError`` and ``AVDeskServerError``) to handle errors.


AVDeskError
-----------

This is a basic exception. All the other ``AVDesk`` family exceptions classes are inhereted from it.

Use it to handle any type of error connected with pyavdesk functionality.

Exception properties:

* ``message`` — Error description returned by *dwavdapi* library or generated by pavdesk.
* ``lib_function`` — dwavdapi library function name on which execution error has occured.
* ``lib_errno`` — Error code returned by *dwavdapi* library.
* ``lib_function_args`` — Arguments passed to *dwavdapi* library function.

Example::

    # Trying to get non-existing station by its ID leads to AVDeskError exception also.
    try:
        station = av_server.get_station('non_existing_station_id')
    except pyavdesk.AVDeskError as e:
        print 'ERROR at `%s`: %s. Code:  %s. Description: %s.' % (e.lib_function, e.lib_errno, e)


AVDeskLibraryError
------------------

This exception class is inhereted from ``AVDeskError`` and is raised when pyavdesk fails to communicate with *dwadvapi* library or there is an exception in library itself.

Use it to handle pure library errors.

Example::

    # Handling hypothetical library error while getting `Everyone` group from server.
    try:
        everyone = av_server.get_group(pyavdesk.META_GROUP_IDS['EVERYONE'])
    except AVDeskLibraryError:
        print 'ERROR at `%s`. Code: %s. Description: %s.' % (e.lib_function, e.lib_errno, e)


AVDeskServerError
-----------------

This exception class is inhereted from ``AVDeskError`` and is raised when *dwadvapi* library recieved an error response from server.

Use it to handle server errors.

Example::

    # Trying to get non-existing tariff by its ID leads to AVDeskServerError exception.
    try:
        subtariff = av_server.get_tariff('non_existing_tariff_id')
    except pyavdesk.AVDeskServerError as e:
        print e
        
