且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将参数传递给JHipster中的自定义错误消息?

更新时间:2023-01-10 14:59:02

Jhipster 6.6 以来,此情况已完全改变,不推荐使用CustomParameterizedException,而使用Zalando的问题库.您可以在ExceptionTranslator中看到jhipster在使用它.

This has completely changed since Jhipster 6.6, CustomParameterizedException is deprecated in favor of Zalando's Problem Library. You can see jhipster using it in the ExceptionTranslator.

这是现在的工作方式

    throw Problem.builder()
        .withStatus(Status.BAD_REQUEST)
        .withTitle("Out of stock")
        .with("message","myjhipsterApp.myentity.error.itBeAllGone")
        .with("param1", "hello there").with("param2", "more hello")
        .build();

自定义错误消息已翻译,并存在于myentity.json中,通常不在global.json中.

Custom error messages are translated and are in your myentity.json, not typically in global.json.

有关如何处理Spring MVC REST错误的更多信息,JHipster使用 Zalando的问题Spring Web库,以便提供基于JSON的丰富错误消息.

for more info on how to handle Spring MVC REST errors, JHipster uses Zalando’s Problem Spring Web library, in order to provide rich, JSON-based error messages.