Can't get the global exception error message? You may also be careless! ! !

  • The problem leads: When placing an order for a product, the user did not select an address and used a global exception to be thrown back to the front-end prompt. The global exception error message can be obtained locally, but it cannot be obtained when deployed to the test environment.
  • Reason: Because of carelessness, the error message returned by the global exception is e.getMessage but the error message I got is taken

Insert picture description here

  • Wrong way
 /**
     * 接口 业务异常
     */
    @ResponseBody
    @ExceptionHandler(ApiMallPlusException.class)
    public Object ApiMallPlusException(ApiMallPlusException e) {
    
    
    //错误的取法 e.getMessage()  应该取e.getErrmsg()
        log.error(e.getMessage(), e);
        R result = R.failed(500, e.getMessage());
        return result;
    }
  • The correct method:
    Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_45528650/article/details/112860941