"...git@gitlab.schbrain.com:panwangnan/schbrain-parent.git" did not exist on "75c65eda527b0aee2255b005dce572fee90921c8"
Commit 53653216 authored by liaozan's avatar liaozan 🏀

Avoid evaluate variable everytime

parent f1a45790
...@@ -12,12 +12,18 @@ import org.springframework.core.Ordered; ...@@ -12,12 +12,18 @@ import org.springframework.core.Ordered;
*/ */
public class DefaultExceptionTranslator implements ExceptionTranslator { public class DefaultExceptionTranslator implements ExceptionTranslator {
private final boolean isProduction;
public DefaultExceptionTranslator() {
this.isProduction = EnvUtils.isProduction();
}
@Override @Override
public ResponseDTO<String> translate(Throwable throwable, int code, int action, String message) { public ResponseDTO<String> translate(Throwable throwable, int code, int action, String message) {
if (throwable instanceof BaseException) { if (throwable instanceof BaseException) {
return ResponseDTO.error((BaseException) throwable); return ResponseDTO.error((BaseException) throwable);
} }
if (EnvUtils.isProduction() || StringUtils.isBlank(message)) { if (isProduction || StringUtils.isBlank(message)) {
return ResponseDTO.error("系统错误", code); return ResponseDTO.error("系统错误", code);
} }
return ResponseDTO.error(message, code, action); return ResponseDTO.error(message, code, action);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment