简体   繁体   English

WSO2 REST API 中的 EI 自定义异常或错误消息

[英]WSO2 EI custom exception or error message in REST API

Can we create custom exception in a REST API?我们可以在 REST API 中创建自定义异常吗? We can use Fault mediator for proxy services.我们可以将故障中介用于代理服务。 Do we have same kind of option for API's as well.我们是否也有相同的 API 选项。

I need this because I'm using fault sequence to log errors in third party system.我需要这个,因为我正在使用故障序列来记录第三方系统中的错误。 For this purpose once error is thrown I'm sending custom message to a REST API.为此,一旦引发错误,我将向 REST API 发送自定义消息。 Since this log message is success I'm not getting an error to original client who calling my rest api and end up with 200 OK.由于此日志消息是成功的,因此调用我的 rest api 并最终得到 200 OK 的原始客户没有收到错误消息。

So can we create a custom fault once after fault sequence is invoked?那么我们可以在调用故障序列后创建一个自定义故障吗?

Yes, you can create a custom fault sequence and add it inside the API.是的,您可以创建自定义故障序列并将其添加到 API 中。 Further, you can modify it as you required.此外,您可以根据需要对其进行修改。

Sample API:样品 API:

<api xmlns="http://ws.apache.org/ns/synapse" name="testAPI" context="/test12" version="1.0" version-type="context">
   <resource methods="GET" faultSequence="CustomFault">
      <inSequence>
         <log level="custom">
            <property name="message" value="Inside the API"/>
         </log>
      </inSequence>
   </resource>
</api>

Sample Fault Sequence:示例故障序列:

<?xml version="1.0" encoding="UTF-8"?>
<sequence name="CustomFault" xmlns="http://ws.apache.org/ns/synapse">
    <log level="full">
        <property name="MESSAGE" value="Executing default 'fault' sequence"/>
        <property expression="get-property('ERROR_CODE')"
            name="ERROR_CODE" xmlns:ns="http://org.apache.synapse/xsd" xmlns:ns3="http://org.apache.synapse/xsd"/>
        <property expression="get-property('ERROR_MESSAGE')"
            name="ERROR_MESSAGE"
            xmlns:ns="http://org.apache.synapse/xsd" xmlns:ns3="http://org.apache.synapse/xsd"/>
    </log>
  </sequence>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM