[fix] refactor error handling