Monday, June 29, 2015

How to send specific status code and message based on different authentication faliures WSO2 API Manager

In WSO2 API Manager all authentication faliures will hit auth failure handler. There you will be able to change message body, content, header based on internal error codes.
As example if we got resource not found error while doing token validation then Error Code will be 900906. So in same way we will have different error codes for different failures.

So in this sample will generate custom message for resource not found issues while doing token validation.
For this we will specifically check error code 900906 and then route request to specific sequence.

Please refer following sequence and change to auth_failure_handler to call sequence.


<sequence name="_auth_failure_handler_" xmlns="">
    <property name="error_message_type" value="application/xml"/>    
    <filter source="get-property('ERROR_CODE')" regex="900906">
          <sequence key="sample"/>
    <sequence key="_build_"/>


<?xml version="1.0" encoding="UTF-8"?>
<sequence xmlns="" name="sample">
    <payloadFactory media-type="xml">
            <am:fault xmlns:am="">   
                <am:message>Resource not found</am:message>
                <am:description>Wrong http method</am:description>
    <property name="RESPONSE" value="true"/>
    <header name="To" action="remove"/>
    <property name="HTTP_SC" value="405" scope="axis2"/>
    <property name="messageType" value="application/xml" scope="axis2"/>

No comments:

Post a Comment