class ErrorMapper {

    public static ErrorStatusInfo mapError(final Exception exception, final Map<String, Integer> httpResponseCodeMappings,
            final Integer defaultResponseCode) {

        SyndesisConnectorException sce;
        if (isOrCausedBySyndesisConnectorException(exception)) {
            sce = extract(exception);
        } else {
            sce = fromRuntimeException(exception, httpResponseCodeMappings.keySet());
        }
        if (sce == null) { //catch all server error
            sce = SyndesisConnectorException.from(exception);
        }
        Integer responseCode = httpResponseCodeMappings.get(sce.getCategory()) != null ?
                httpResponseCodeMappings.get(sce.getCategory()): defaultResponseCode;
        return new ErrorStatusInfo(responseCode, sce.getCategory(),
            Optional.ofNullable(sce.getMessage()).orElse("no message"), deriveErrorName(sce));
    }

    private  ErrorMapper();

}