<?xml version="1.0" encoding="UTF-8"?>
<sequence name="TimeoutFailureSeq" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
    <log description="Log error details in case of failure" level="full">
        <property name="MESSAGE" value="An unexpected error occurred."/>
        <property expression="$ctx:SYNAPSE_REST_API" name="REST_API"/>
        <property expression="$ctx:ERROR_CODE" name="ERROR_CODE"/>
        <property expression="$ctx:ERROR_MESSAGE" name="ERROR_MESSAGE"/>
        <property expression="$ctx:ERROR_DETAIL" name="ERROR_DETAIL"/>
        <property expression="$ctx:ERROR_EXCEPTION" name="ERROR_EXCEPTION"/>
    </log>
    <payloadFactory description="Build payload with error information" media-type="json">
        <format>{
   "MESSAGE": "An unexpected error occurred.",
   "REST_API": "$1",
   "ERROR_CODE": $2,
   "ERROR_MESSAGE": $3,
   "ERROR_DETAIL": $4,
   "ERROR_EXCEPTION": $5
}</format>
        <args>
            <arg evaluator="xml" expression="$ctx:SYNAPSE_REST_API"/>
            <arg evaluator="xml" expression="$ctx:ERROR_CODE"/>
            <arg evaluator="xml" expression="$ctx:ERROR_MESSAGE"/>
            <arg evaluator="xml" expression="$ctx:ERROR_DETAIL"/>
            <arg evaluator="xml" expression="$ctx:ERROR_EXCEPTION"/>
        </args>
    </payloadFactory>
    <respond description="Respond back to client with custom error payload"/>
</sequence>
