【pinyin】更新拼音模块异常

pull/3/head
fengshuonan 2021-02-08 10:38:08 +08:00
parent 13877758f9
commit 98ee4d2484
2 changed files with 7 additions and 9 deletions

View File

@ -1,5 +1,6 @@
package cn.stylefeng.roses.kernel.pinyin.api.exception; package cn.stylefeng.roses.kernel.pinyin.api.exception;
import cn.hutool.core.util.StrUtil;
import cn.stylefeng.roses.kernel.pinyin.api.constants.PinyinConstants; import cn.stylefeng.roses.kernel.pinyin.api.constants.PinyinConstants;
import cn.stylefeng.roses.kernel.rule.exception.AbstractExceptionEnum; import cn.stylefeng.roses.kernel.rule.exception.AbstractExceptionEnum;
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException; import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
@ -14,12 +15,12 @@ import lombok.Getter;
@Getter @Getter
public class PinyinException extends ServiceException { public class PinyinException extends ServiceException {
public PinyinException(AbstractExceptionEnum exceptionEnum, String userTip) {
super(PinyinConstants.PINYIN_MODULE_NAME, exceptionEnum.getErrorCode(), userTip);
}
public PinyinException(AbstractExceptionEnum exceptionEnum) { public PinyinException(AbstractExceptionEnum exceptionEnum) {
super(PinyinConstants.PINYIN_MODULE_NAME, exceptionEnum); super(PinyinConstants.PINYIN_MODULE_NAME, exceptionEnum);
} }
public PinyinException(AbstractExceptionEnum exception, Object... params) {
super(PinyinConstants.PINYIN_MODULE_NAME, exception.getErrorCode(), StrUtil.format(exception.getUserTip(), params));
}
} }

View File

@ -1,6 +1,5 @@
package cn.stylefeng.roses.kernel.pinyin; package cn.stylefeng.roses.kernel.pinyin;
import cn.hutool.core.util.StrUtil;
import cn.stylefeng.roses.kernel.pinyin.api.PinYinApi; import cn.stylefeng.roses.kernel.pinyin.api.PinYinApi;
import cn.stylefeng.roses.kernel.pinyin.api.exception.PinyinException; import cn.stylefeng.roses.kernel.pinyin.api.exception.PinyinException;
import net.sourceforge.pinyin4j.PinyinHelper; import net.sourceforge.pinyin4j.PinyinHelper;
@ -107,8 +106,7 @@ public class PinyinServiceImpl implements PinYinApi {
} }
return finalPinyinString.toString(); return finalPinyinString.toString();
} catch (BadHanyuPinyinOutputFormatCombination e1) { } catch (BadHanyuPinyinOutputFormatCombination e1) {
String userTip = StrUtil.format(PARSE_ERROR.getUserTip(), e1.getMessage()); throw new PinyinException(PARSE_ERROR, e1.getMessage());
throw new PinyinException(PARSE_ERROR, userTip);
} }
} }
@ -182,8 +180,7 @@ public class PinyinServiceImpl implements PinYinApi {
} }
} }
} catch (BadHanyuPinyinOutputFormatCombination e) { } catch (BadHanyuPinyinOutputFormatCombination e) {
String userTip = StrUtil.format(PARSE_ERROR.getUserTip(), e.getMessage()); throw new PinyinException(PARSE_ERROR, e.getMessage());
throw new PinyinException(PARSE_ERROR, userTip);
} }
return hanyupinyin.toString(); return hanyupinyin.toString();