For partners that build or integrate commercially available applications and service solutions with the Oracle Cloud Platform
For partners that provide implementation or managed services around Oracle Cloud Applications
Is there a way to configure a REST integration endpoint such that I can pass back either a success JSON response or a failure JSON response?
Currently when I'm configuring the endpoint response inline JSON it appears I can only put in the success JSON response so how would I get it to also expect a failure JSON response which could look completely different to the success response?
Thanks
Mark
Comment
Hi Mark,
While providing the sample json at Response, provide consolidate (success fields + error fields) json. In case of Success,map only success fields and in case of error map only error fields.
Regards,
Ankur Jain
Be the first to rate this
|
Sign in to rate this
Thanks Ankur .
So I can just put both the success and failure JSON responses in the one inline JSON response box?
Regards
Mark
Be the first to rate this
|
Sign in to rate this
Yes you can as
{
"succcess_field1":"",
"succcess_field1":"",
"fail_field1":"",
"fail_field2":""
}
See YouTube channel to learn more in OIC https://www.youtube.com/c/TechSupper
Regards,
Ankur
Be the first to rate this
|
Sign in to rate this
Not possible actually. In case of failure response what is the response code? 2XX or any other?
Be the first to rate this
|
Sign in to rate this
It's a 400 response in this case.
Are you saying the above response from Ankur won't work?
Be the first to rate this
|
Sign in to rate this
If you need 400 response code, please see below blog
https://www.techsupper.com/2019/05/http-error-responses-in-rest-api-oracle-integration-cloud.html
Regards,
Ankur
Be the first to rate this
|
Sign in to rate this
Yes, it won't work! The response JSON configuration only works for success response, i.e, response code 200. For 4XX/5XX, the control goes to exception and the response payload received will be wrapped into inbuilt fault message which can be parsed using with string functions.
Be the first to rate this
|
Sign in to rate this
Hemanth, you are correct in case response code 4XX/5XX. In case of failure if 200 response is required then my statement is true.
Regards,
Ankur
Be the first to rate this
|
Sign in to rate this
ok thanks Ankur.
Regards
Mark
Be the first to rate this
|
Sign in to rate this
There could be variety of reasons a failure can happen. At transport/http layer to application level. You get http error code back if the request is bad (malformed, lacking/invalid credential etc) you get 4xx and if server is not available to process the request you get 5xx errors back. In such cases you cannot return custom error message. Once the request is successfully delivered (http 200) to application you can write fault handling to handle error/faults and return custom message.
Be the first to rate this
|
Sign in to rate this
Thanks for all the replies.
Regards
Mark
Be the first to rate this
|
Sign in to rate this
Is there anything I can do within the integration to detect a 4XX/5XX response?
Be the first to rate this
|
Sign in to rate this
Any response code other than 2XX is a fault code. So adapter wraps the response in APIInvocationError fault object (inbuilt for rest adapter). You can wrap the invoke in a scope and in Scope Fault Handler you can catch the APIInvocationError fault.
Be the first to rate this
|
Sign in to rate this
Thanks Hemanth
I looked at your previous link (https://www.techsupper.com/2019/05/http-error-responses-in-rest-api-oracle-integration-cloud.html) but still could quite see where to do what you are suggesting.
Do you have any other examples?
Regards
Mark
Be the first to rate this
|
Sign in to rate this
Check here.
Be the first to rate this
|
Sign in to rate this
I had a look but it's not very clear - do you have any examples?
Be the first to rate this
|
Sign in to rate this