code: public static Optional<CipResponseException> extract(Throwable ex) {
          if (ex instanceof CipResponseException) {
              return Optional.of((CipResponseException) ex);
          } else {
              Throwable cause = ex.getCause();
              return cause != null ?
                  extract(cause) : Optional.empty();
          }
      }
docs: If {@code ex} is a {@link CipResponseException}, or if a {@link CipResponseException} can be found by walking
  the exception cause chain, return it.
  
  @param ex the {@link Throwable} to extract from.
  @return a {@link CipResponseException} if one was present in the exception chain.