callSuper=true) (publicclassOpenRuntimeExceptionextendsRuntimeException { protectedStringerrorCode="Internal Server Error"; protectedStringmessage="No value present"; protectedintstatus=500; publicOpenRuntimeException(OpenErrorCodessoErrorCode) { this(ssoErrorCode, (Object[]) null); } OpenRuntimeException(OpenErrorCodessoErrorCode, Object... params) { this(ssoErrorCode, null, params); } OpenRuntimeException(OpenErrorCodessoErrorCode, Throwablecause, Object... params) { this.errorCode=ssoErrorCode.name(); this.status=ssoErrorCode.getStatus(); this.message=ssoErrorCode.getMessage(params); if (cause!=null) { initCause(cause); } } publicStringgetMessage() { returnmessage; } }
publicinterfaceOpenErrorCode { /*** description: 获取异常的name** @return {@link String}* @author <a href="mailto:joshualwork@163.com">joshua_liu</a>* @date 2021/4/25 9:11*/Stringname(); /*** description: 响应的状态码** @return {@link int}* @author <a href="mailto:joshualwork@163.com">joshua_liu</a>* @date 2021/4/25 9:12*/intgetStatus(); /*** description:** @param cause 异常对象* @param params 格式化参数* @return {@link OpenRuntimeException}* @author <a href="mailto:joshualwork@163.com">joshua_liu</a>* @date 2021/4/25 9:58*/defaultOpenRuntimeExceptionruntimeException(Throwablecause, Object... params) { returnnewOpenRuntimeException(this, cause, params); } /*** description:** @param params 格式化参数* @return {@link OpenRuntimeException}* @throws* @author <a href="mailto:joshualwork@163.com">joshua_liu</a>* @date 2021/4/25 10:00*/defaultOpenRuntimeExceptionruntimeException(Object... params) { returnnewOpenRuntimeException(this, params); } /*** description:** @param cause 异常* @return {@link OpenRuntimeException}* @author <a href="mailto:joshualwork@163.com">joshua_liu</a>* @date 2021/4/25 16:40*/defaultOpenRuntimeExceptionruntimeException(Throwablecause) { returnnewOpenRuntimeException(this, cause); } /*** description:** @param params 格式化参数* @param locale 地区* @return {@link String}* @author <a href="mailto:joshualwork@163.com">joshua_liu</a>* @date 2021/4/25 9:13*/defaultStringgetMessage(Localelocale, Object... params) { Stringmessage="NO MESSAGE!!!"; if (locale==null) { locale=Locale.getDefault(); } try { Stringformatter=Objects.equals("OpenExceptionEnum", this.getClass().getSimpleName()) ?"META-INF.{0}" : "i18n.exception.{0}"; ResourceBundlebundle=ResourceBundle .getBundle(MessageFormat.format(formatter, this.getClass().getSimpleName()), locale); message=bundle.getString(this.name()); returnnewMessageFormat(message).format(params); } catch (Throwablee) { if (!(einstanceofMissingResourceException)) { e.printStackTrace(); } message=Objects.isNull(params) ?message : newMessageFormat("{0}").format(params); returnmessage; } } /*** description:** @param params 格式化参数* @return {@link String}* @author <a href="mailto:joshualwork@163.com">joshua_liu</a>* @date 2021/4/25 9:56*/defaultStringgetMessage(Object... params) { returngetMessage(Locale.getDefault(), params); } }