public static Errors forException(Throwable t) {
        Throwable cause = maybeUnwrapException(t);
        Class<?> clazz = cause.getClass();
        while (clazz != null) {
            Errors error = CLASS_TO_ERROR.get(clazz);
            if (error != null)
                return error;
            clazz = clazz.getSuperclass();
        }
        return UNKNOWN_SERVER_ERROR;
    }
Return the error instance associated with this exception or any of its superclasses (or UNKNOWN if there is none).
If there are multiple matches in the class hierarchy, the first match starting from the bottom is used.
clients/src/main/java/org/apache/kafka/common/protocol/Errors.java