class MsoCommonUtils {

    protected MsoException neutronExceptionToMsoException(OpenStackBaseException e, String context) {
        MsoException me = null;

        if (e instanceof OpenStackResponseException) {
            OpenStackResponseException re = (OpenStackResponseException) e;

            try {
                // Failed Neutron calls return an NeutronError entity body
                NeutronError error = re.getResponse().getErrorEntity(NeutronError.class);
                logger.error("{} {} Openstack Neutron Error on {} {}", MessageEnum.RA_CONNECTION_EXCEPTION,
                        ErrorCode.DataError.getValue(), context, error);
                me = new MsoOpenstackException(re.getStatus(), error.getType(), error.getMessage());
            } catch (Exception e2) {
                // Couldn't parse body as a NeutronError. Report the HTTP error.
                logger.error("{} {} Openstack HTTP Error on {}: {}, {}", MessageEnum.RA_CONNECTION_EXCEPTION,
                        ErrorCode.DataError.getValue(), context, re.getStatus(), e.getMessage(), e2);
                me = new MsoOpenstackException(re.getStatus(), re.getMessage(), null);
            }

            // Add the context of the error
            me.addContext(context);

            // Generate an alarm for 5XX and higher errors.
            if (re.getStatus() >= 500) {
                logger.error("{} {} OpenStackBaseException with response code {} on {}: ",
                        MessageEnum.RA_CONNECTION_EXCEPTION, ErrorCode.DataError.getValue(), re.getStatus(), context,
                        e);
            }
        } else if (e instanceof OpenStackConnectException) {
            OpenStackConnectException ce = (OpenStackConnectException) e;

            me = new MsoIOException(ce.getMessage());
            me.addContext(context);

            // Generate an alarm for all connection errors.

            logger.error("{} {} Openstack Neutron Connection error on {}: ", MessageEnum.RA_CONNECTION_EXCEPTION,
                    ErrorCode.DataError.getValue(), context, e);
        }

        return me;
    }

}