使Alfresco Web脚本将错误500显示为JSON而不是HTML [英] Make Alfresco Web Script show error 500 as JSON rather than HTML
问题描述
我正在编写一个Alfresco Web脚本,它将被外部计算机使用。
I am writing an Alfresco Web Script that will be consumed by external computers.
当我抛出WebScriptException时,我希望错误500伴随错误网页而不是HTML,而是JSON,以便外部计算机可以对其进行解析。现在,我得到这个:
When I throw a WebScriptException, I would like the error 500 to come with an error page in JSON, rather than HTML, so that the external computers can parse it. Right now I am getting this:
如何
我看到某些Web脚本设法将错误页面生成为JSON(不过对于错误401,所以可能在Web Script实际被调用之前):
I see that some Web Scripts manage to produce error pages as JSON (for error 401 though, so probably before the Web Script actually gets called):
推荐答案
您可以为每个状态代码创建一个专用标记。如果您转到此网页 http://docs.alfresco.com /5.2/concepts/ws-component-name.html 并滚动到 FreeMarker模板-响应状态,您可以看到一些示例。
You can create a freemarker dedicated for each status code. If you go to this web page http://docs.alfresco.com/5.2/concepts/ws-component-name.html and scroll to "FreeMarker Templates - Response status", you can see some examples.
引用为5.2:
响应状态代码文档文件名遵循Web脚本框架定义的命名约定
。按照以下顺序搜索适当的响应
状态代码模板:
Response status code document file names adhere to a naming convention as defined by the Web Script Framework. The appropriate response status code template is searched for in the following order:
- 与网络位于同一文件夹中的模板用于呈现特定状态代码响应的脚本描述文档
,它遵循命名约定< web脚本ID> .http方法><格式>。<状态代码> .ftl
- 与Web脚本描述文件位于同一文件夹中的模板,用于呈现任何状态代码
的响应,并遵守命名约定<网络脚本ID>。< http方法>。< format> .status.ftl
- 一个包-位于Web脚本包中但如果未找到的级别模板,则在父包层次结构中进行搜索,将
向上移至根包,以呈现任何状态码的响应,
坚持命名约定< format> .status.ftl
- 模板定位根包中的d,用于呈现特定状态代码的HTML响应,该代码遵循命名
约定< status code> .ftl
- 位于根包中的模板,用于呈现任何状态代码的HTML响应,该模板遵循命名约定:
status.ftl
- A template located in the same folder as the web script description document for rendering a specific status code response,
which adheres to the naming convention
<web script id>.<http method>.<format>.<status code>.ftl
- A template located in the same folder as the web script description document for rendering a response of any status code,
which adheres to the naming convention
<web script id>.<http method>.<format>.status.ftl
- A package-level template located in the package of the web script but, if not found, is searched for in the parent package hierarchy, up
to the root package for rendering a response of any status code, which
adheres to the naming convention
<format>.status.ftl
- A template located in the root package for rendering an HTML response for the specific status code, which adheres to the naming
convention
<status code>.ftl
- A template located in the root package for rendering an HTML response of any status code, which adheres to the naming convention:
status.ftl
这篇关于使Alfresco Web脚本将错误500显示为JSON而不是HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!