Added ApiErrorException and improved overall exception handling