12 changed files with 208 additions and 80 deletions
			
			
		@ -0,0 +1,96 @@ | 
				
			|||||
 | 
					/** | 
				
			||||
 | 
					 * Copyright (c) 2018 人人开源 All rights reserved. | 
				
			||||
 | 
					 * <p> | 
				
			||||
 | 
					 * https://www.renren.io
 | 
				
			||||
 | 
					 * <p> | 
				
			||||
 | 
					 * 版权所有,侵权必究! | 
				
			||||
 | 
					 */ | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					package com.epmet.commons.tools.exception; | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					import com.epmet.commons.tools.constant.StrConstant; | 
				
			||||
 | 
					import com.epmet.commons.tools.utils.MessageUtils; | 
				
			||||
 | 
					import org.apache.commons.lang3.StringUtils; | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					/** | 
				
			||||
 | 
					 * Epmet产品 自定义异常 | 
				
			||||
 | 
					 * | 
				
			||||
 | 
					 * @author Mark sunlightcs@gmail.com | 
				
			||||
 | 
					 * @since 1.0.0 | 
				
			||||
 | 
					 */ | 
				
			||||
 | 
					public class EpmetException extends RuntimeException { | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					    private static final long serialVersionUID = 1L; | 
				
			||||
 | 
					    /** | 
				
			||||
 | 
					     * desc:错误码 | 
				
			||||
 | 
					     */ | 
				
			||||
 | 
					    protected int code; | 
				
			||||
 | 
					    /** | 
				
			||||
 | 
					     * 显示给客户的消息 | 
				
			||||
 | 
					     */ | 
				
			||||
 | 
					    protected String msg; | 
				
			||||
 | 
					    /** | 
				
			||||
 | 
					     * 内部消息,用于服务之间传递错误信息,排错用 | 
				
			||||
 | 
					     */ | 
				
			||||
 | 
					    protected String internalMsg; | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					    /** | 
				
			||||
 | 
					     * desc:指定错误码异常 外部异常内容为错误码对应的异常 | 
				
			||||
 | 
					     * @param code | 
				
			||||
 | 
					     */ | 
				
			||||
 | 
					    public EpmetException(int code) { | 
				
			||||
 | 
					        this(code, StrConstant.EPMETY_STR); | 
				
			||||
 | 
					    } | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					    /** | 
				
			||||
 | 
					     * desc:指定内部错误消息的异常 外部异常内容为错误码对应的异常 | 
				
			||||
 | 
					     * @param code | 
				
			||||
 | 
					     * @param internalMsg | 
				
			||||
 | 
					     */ | 
				
			||||
 | 
					    public EpmetException(int code, String internalMsg) { | 
				
			||||
 | 
					        super(internalMsg); | 
				
			||||
 | 
					        this.code = code; | 
				
			||||
 | 
					        if (StringUtils.isBlank(internalMsg)) { | 
				
			||||
 | 
					            this.internalMsg = EpmetErrorCode.getMsg(code); | 
				
			||||
 | 
					            if (StringUtils.isBlank(this.internalMsg)) { | 
				
			||||
 | 
					                this.internalMsg = MessageUtils.getMessage(code, internalMsg); | 
				
			||||
 | 
					            } | 
				
			||||
 | 
					        } else { | 
				
			||||
 | 
					            this.internalMsg = internalMsg; | 
				
			||||
 | 
					        } | 
				
			||||
 | 
					    } | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					    /** | 
				
			||||
 | 
					     * desc:指定错误码 内外部错误消息异常 | 
				
			||||
 | 
					     * @param code | 
				
			||||
 | 
					     * @param internalMsg | 
				
			||||
 | 
					     * @param externalMsg | 
				
			||||
 | 
					     */ | 
				
			||||
 | 
					    public EpmetException(int code, String internalMsg, String externalMsg) { | 
				
			||||
 | 
					        this(code, internalMsg); | 
				
			||||
 | 
					        this.msg = externalMsg; | 
				
			||||
 | 
					    } | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					    /** | 
				
			||||
 | 
					     * desc:指定内部消息异常 外部错误码及消息为8000,服务器开小差 | 
				
			||||
 | 
					     * @param internalMsg | 
				
			||||
 | 
					     */ | 
				
			||||
 | 
					    public EpmetException(String internalMsg) { | 
				
			||||
 | 
					        super(internalMsg); | 
				
			||||
 | 
					        this.code = EpmetErrorCode.SERVER_ERROR.getCode(); | 
				
			||||
 | 
					        this.internalMsg = internalMsg; | 
				
			||||
 | 
					    } | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					    public int getCode() { | 
				
			||||
 | 
					        return code; | 
				
			||||
 | 
					    } | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					    public String getMsg() { | 
				
			||||
 | 
					        return msg; | 
				
			||||
 | 
					    } | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					    public String getInternalMsg() { | 
				
			||||
 | 
					        return internalMsg; | 
				
			||||
 | 
					    } | 
				
			||||
 | 
					} | 
				
			||||
					Loading…
					
					
				
		Reference in new issue