Mule Rest Exception Handling

Mule flows:

<jersey:resources doc:name="REST">
<component class="com.test.qb.rest.MapIIFContent"/>
<jersey:exception-mapper class="com.test.qb.exception.IIFExceptionMapper" />
</jersey:resources>
<catch-exception-strategy doc:name="Audit Exception" >      
    <set-variable variableName="status" value="Failure" doc:name="Status"/>
    <flow-ref name="QB:audit" doc:name="audit"/>
    <http:response-builder status="500" contentType="application/json" doc:name="Status Code"/>
</catch-exception-strategy>
<logger message=" ===Reached here====" level="INFO" doc:name="Logger"/> <!-- Line 10-->

Java Rest Component:

Leisure component:

try{
    String s =null;
    s.toString();// throw nullpointer exception
} catch (IIFException e) {
    return Response.status(500).entity(e.getMessage()).type("Application/json").build();
}
return Response.ok(res).build();

When I run this, it goes into the catch block in the Java Rest component with error status 500. But in Mule threads, I expect the thread to reach

'catch-exception-strategy doc: name = "Audit Exception">

but he doesn’t reach it, but reaches line 10. How can I handle this?

+4
source share
1 answer

I made a rest component to throw a checked custom exception instead of returning the status of the response response:

try{
    String s =null;
    s.toString();
} catch (IIFException e) {
    throw new IIFException(e.toString(),e.getCause());
}
return Response.ok(res).build();

And in my exception threads I did it like:

<catch-exception-strategy doc:name="Audit Exception" >
    <expression-component doc:name="Create error response"><![CDATA[#[payload = "{\"status\":\"error\", \"message\":\"" + exception.cause.message + "\"}"]]]></expression-component>
    <http:response-builder status="500" contentType="application/json" doc:name="Status Code"/>
</catch-exception-strategy>
+2
source

All Articles