Add ApiException class
Improve errors handling; Refactor client. Update test script