如何在调用WSO2 API Manager中的API资源时更改不允许的HTTP方法的错误消息?

huangapple go评论61阅读模式
英文:

how to change error message for not allowed htttp methods when calling an API resource in wso2 API manager?

问题

我在WSO2 API Manager中创建了一个REST API,为例子的"delivery"资源仅分配了POST方法来调用此API资源。默认情况下,当使用其他HTTP方法调用此API时,API Manager会抛出以下响应:

<am:fault xmlns:am="http://wso2.org/apimanager">
  <am:code>405</am:code>
  <am:type>Status report</am:type>
  <am:message>Runtime Error</am:message>
  <am:description>Method not allowed for given API resource</am:description>
</am:fault>

在某些HTTP方法,如COPY方法中,它会抛出400 Bad Request。首先,我想在响应中不显示上面的消息,只返回状态码,而不返回响应消息。其次,只对POST方法之外的所有HTTP方法显示405 Method Not Allowed。

英文:

I created a rest api in wso2 api manager publisher add add a resource for example delivery and only assign post method for calling this api resource , by default when use other http methods for calling this api , api manager throws below response :

&lt;am:fault xmlns:am=&quot;http://wso2.org/apimanager&quot;&gt;
  &lt;am:code&gt;405&lt;/am:code&gt;
  &lt;am:type&gt;Status report&lt;/am:type&gt;
  &lt;am:message&gt;Runtime Error&lt;/am:message&gt;
  &lt;am:description&gt;Method not allowed for given API resource&lt;/am:description&gt;
&lt;/am:fault&gt;

and in some http methods like COPY it throws 400 bad request ,first I want to don't show above message in response and only give back the status code and nothing in response message
and second show 405 method not allowed for all http methods except POST method.

答案1

得分: 1

你可以修改默认的故障序列以更改消息。请查看此文档

英文:

You can modify the default fault sequence in order the change the message. Take a look at this document.

huangapple
  • 本文由 发表于 2023年4月17日 16:31:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/76033145.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定