Exception 清除自定义异常的消息

Exception 清除自定义异常的消息,exception,grails,Exception,Grails,在我的grails应用程序中,我有一个自定义的InvalidTokenException,如下所示: class InvalidTokenException extends Exception{ public InvalidTokenException() {} public InvalidTokenException(String message) { super(message); } } throw new InvalidTokenException(

在我的grails应用程序中,我有一个自定义的
InvalidTokenException
,如下所示:

class InvalidTokenException extends Exception{  

  public InvalidTokenException() {}

  public InvalidTokenException(String message)
  {
    super(message);
  }  
}
throw new InvalidTokenException("Invalid token : '${word}'")
catch(e)
    {
        //send the exception to the client for rendering an error message.
        render(status: 400, text: e)
        return false //stops further execution
    }
我将为我的服务投入如下:

class InvalidTokenException extends Exception{  

  public InvalidTokenException() {}

  public InvalidTokenException(String message)
  {
    super(message);
  }  
}
throw new InvalidTokenException("Invalid token : '${word}'")
catch(e)
    {
        //send the exception to the client for rendering an error message.
        render(status: 400, text: e)
        return false //stops further execution
    }
我在控制器中捕获并呈现给客户端,如下所示:

class InvalidTokenException extends Exception{  

  public InvalidTokenException() {}

  public InvalidTokenException(String message)
  {
    super(message);
  }  
}
throw new InvalidTokenException("Invalid token : '${word}'")
catch(e)
    {
        //send the exception to the client for rendering an error message.
        render(status: 400, text: e)
        return false //stops further execution
    }
虽然我想删除消息,它只包含文本“Invalid token:word”,而不是“Exception uk.co.litecolab.exceptions.InvalidTokenException无效token:word”


有什么办法吗?

将其更改为
render(状态:400,文本:e.message)
,因为您当前正在利用
e
自动转换为字符串的功能,该功能调用
toString()
方法。直接调用
getMessage()
通常更有意义,并且可以满足您的需要。

谢谢,效果非常好。我自己应该抓到的,这是一个漫长的周末。。