Refactor handling of COM error codes.