/**
 * Copyright 2018-2020 stylefeng & fengshuonan (sn93@qq.com)
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package com.sunxung.factoring.component.exception;


/**
 * 业务异常的封装
 */
public class ServiceException extends RuntimeException {

  /**
   * 业务异常码
   */
  private String serviceCode;


  /**
   * http请求状态
   */
  private Integer code;


  private String errorMessage;

  public Integer getCode() {
    return code;
  }

  public void setCode(Integer code) {
    this.code = code;
  }

  public String getErrorMessage() {
    return errorMessage;
  }

  public String getServiceCode() {
    return serviceCode;
  }

  public void setServiceCode(String serviceCode) {
    this.serviceCode = serviceCode;
  }

  public void setErrorMessage(String errorMessage) {
    this.errorMessage = errorMessage;
  }

  public ServiceException(String serviceCode, String errorMessage) {
    this(500);
    this.serviceCode = serviceCode;
    this.errorMessage = errorMessage;
  }

  public ServiceException(Integer code) {
    this.code = code;
  }

  public ServiceException(Integer code, String errorMessage) {
    super(errorMessage);
    this.code = code;
    this.errorMessage = errorMessage;
  }

  public ServiceException(Integer code, String serviceCode, String errorMessage) {
    this.serviceCode = serviceCode;
    this.code = code;
    this.errorMessage = errorMessage;
  }

  /**
   * 异常
   */
  public ServiceException(Integer code, AbstractBaseException exception) {
    super(exception.getMessage());
    this.code = code;
    this.serviceCode = exception.getServiceCode();
    this.errorMessage = exception.getMessage();
  }

  public ServiceException(AbstractBaseException exception) {
    super(exception.getMessage());
    this.code = 500;
    this.serviceCode = exception.getServiceCode();
    this.errorMessage = exception.getMessage();
  }

}
