class ExceptionToProducerResponseConverters {

  public Response convertExceptionToResponse(SwaggerInvocation swaggerInvocation, Throwable e) {
    ExceptionToProducerResponseConverter<Throwable> converter = null;
    Class<?> clazz = e.getClass();
    while (converter == null) {
      converter = exceptionToProducerResponseConverters.get(clazz);
      if (clazz == Throwable.class) {
        break;
      }
      clazz = clazz.getSuperclass();
    }
    if (converter == null) {
      converter = defaultConverter;
    }
    try {
      return converter.convert(swaggerInvocation, e);
    } catch (Throwable throwable) {
      // In case users do not implement correctly and maybe discovered at runtime to cause asycResponse callback hang.
      LOGGER
          .error("ExceptionToProducerResponseConverter {} cannot throw exception, please fix it.", converter.getClass(),
              throwable);
      return Response.failResp(swaggerInvocation.getInvocationType(), e);
    }
  }

  @SuppressWarnings("unchecked") public  ExceptionToProducerResponseConverters();

}