Refactors client's API error handling