package com.dbs.mplus.exception.mobile;

import com.dbs.mplus.framework.FrameworkConstants;
import com.dbs.mplus.framework.exception.MPlusApiServiceException;
import com.dbs.mplus.service.api.MPlusApi;

/**
 * api 호출 시 발생한 예외 
 * @author hyeeun 
 *
 */
public class ApiCallException extends MPlusApiServiceException {
	private static final long serialVersionUID = 7893623351257667839L;
	private MPlusApi callee; 
	
	/**
	 * 생성자 
	 * @param code
	 * @param message
	 * @param ex
	 * @param callee
	 */
	public ApiCallException(String code, String message, Exception ex, MPlusApi callee) {
		this(code, message, callee); 
		if(ex != null) { 
			super.setStackTrace(ex.getStackTrace());
		} 
	}
	/**
	 * 생성자 
	 * @param code
	 * @param message
	 * @param callee
	 */
	public ApiCallException(String code, String message, MPlusApi callee) { 
		super(code, message); 
		this.callee = callee; 
	}
	/**
	 * 어떤 api를 호출하다가 에러가 났는지 반환 
	 * @return
	 */
	public MPlusApi getCallee() { 
		return this.callee; 
	}
	
	@Override 
	public String toString() { 
		StringBuilder builder = new StringBuilder(); 
		
		builder.append(FrameworkConstants.NEW_LINE); 
		builder.append("- API : "); 
		
		if(this.callee == null) { 
			builder.append("정보누락됨"); 
		}
		else {
			builder.append(this.callee); 
		} 
		builder.append(FrameworkConstants.NEW_LINE); 
		builder.append("- Message : ").append(this.getMessage()).append(" (").append(this.getCode()).append(") ").append(FrameworkConstants.NEW_LINE); 
		
		return builder.toString(); 
	}
}
