Wednesday, August 4, 2021

OIC - Fault Return action - Custom HTTP Error response in rest flows

Why Fault return:

The REST adapter allows to expose the HTTP endpoint that HTTP clients can request and returns an HTTP response. On successful call, it gets a HTTP status code with the response. On error, it returns an error response with an HTTP status  belonging to the HTTP error family of codes depending on the fault situation.

Using this Fault return action, we can send custom error response to the consumer. For example,

We can send 400 Bad request, if some manadatory params are missing.

Use case:

We will create an app driven service and use rest service trigger with input query field "id" and response "name". We will create a logic, if id is not empty then harcode a name to the response otherwise we will take a fault return action and send a custom error message to the consumer.

Steps of implementation:

Step1: Create an appdriven integration and drag and drop rest trigger connection and configure :

Endpoint name

URI: /custom

Verb: get

Add and review params for this endpoint

Configure this endpoint to receive the response

Next

Add Query parameter 

Name: id and data type : string

In response section, choose JSON and inline and write as below

{

"Name":"samplename"

}

Next

Done.

Now the integration flow look like:



Step2: add a switch action and add the following condition

Id !=""

And hardcode a name to the response.

Step3: in the otherwise block,  add fault return activity and map the error code, type error details as customized as per your requirement.


Here, I have customize erros as below:

Error code: '400'

Type: '400, Bad Request'

Title: 'id field value is empty or missing'


Now the Integration flow looks as below


Step4: add tracking as id, save, activate and run test with empty id. You will see your customized error:




No comments:

Post a Comment

Featured Post

11g to 12c OSB projects migration points

1. Export 11g OSB code and import in 12c Jdeveloper. Steps to import OSB project in Jdeveloper:   File⇾Import⇾Service Bus Resources⇾ Se...