Error

The element holds the criteria that determines whether a <response> should be classified as a success or an error.

Possible Locations

Attributes


Name Type Description
condition
required
String The condition that decides whether the response is a success or an error.
To learn how to construct a condition, refer to this conditions page.

Note:
  • The error can be given inside the <content> only when it is used as a child element of response.
  • The error defined at the content level holds the highest priority as it allows the configuration of specific conditions for different responses. Conversely, the error added at the operation level is generic, applying to all responses under the particular <operation> and is given the lowest priority.

Samples

Operation

Assume that in the trips resource, we want to define the error condition for the GET operation as follows,

    
copy
Error condition: The value of status should be invalid in the response.

We have already declared the <response> in the <components>. Now, you have to refer to it from the components and add the errors as shown below.

    
copy
<operation method="get" name="GET Trips" category="read"> <error condition="RESPONSE:$.status == 'invalid'" /> <response-ref name="SUCCESS" /> <response-ref name="INVALID_URL_PATTERN" /> <response-ref name="OAUTH_SCOPE_MISMATCH" /> <response-ref name="INVALID_TOKEN" /> </operation>

Content

Let us say that we have two different <content> in a <response>. You want to declare error condition for each of the content.

    
copy
Content type: JSON format { "code": "INVALID_TOKEN", "message": "invalid oauth token", "status": "error" }
    
copy
Content type: XML format <root> <code>INVALID_TOKEN</code> <message>invalid oauth token</message> <success>false</success> </root>

With the above details write the error for each content as follows,

    
copy
<response name="error" status="400"> <content> <encode type="application/json"/> <error condition="RESPONSE:$.status == 'error'"/> <!-- condition for JSON format --> <structure name="wrapper"> <property name="code" type="string" values="INVALID_TOKEN"/> <property name="message" type="string" values="invalid oauth token"/> <property name="status" type="string" values="error"/> </structure> </content> <content> <encode type="application/xml"/> <error condition="RESPONSE:$.success == false" /> <!-- condition for XML format --> <structure> <property type="map"> <xml-format name="root" /> <structure> <property name="code" type="string" values="INVALID_TOKEN" /> <property name="message" type="string" values="invalid oauth token"/ > <property name="success" type="boolean" /> </structure> </property> </structure> </content> </response>

Last Updated 2025-05-30 16:54:59 +0530 +0530