package ru.micord.ervu_eks.exception;

import org.springframework.context.support.MessageSourceAccessor;
import org.springframework.context.support.ResourceBundleMessageSource;
import ru.cg.webbpm.modules.core.runtime.api.LocalizedException;
import ru.cg.webbpm.modules.core.runtime.api.MessageBundleUtils;

public class ConfigExecutorException extends LocalizedException {

  private String forcedMessage = null;

  private static final MessageSourceAccessor MESSAGE_SOURCE = MessageBundleUtils.createAccessor(
      "i18n/exception_handler_messages"
  );;

  public ConfigExecutorException(String code, Throwable cause) {
    super(code, MESSAGE_SOURCE, cause);
  }

  public ConfigExecutorException(String code, Throwable cause, String forcedMessage) {
    super(code, MESSAGE_SOURCE, cause);
    this.forcedMessage = forcedMessage;
  }

  @Override
  public String getLocalizedMessage() {
    if (forcedMessage != null) {
      return forcedMessage;
    } else {
      return super.getLocalizedMessage();
    }
  }

}
