How To Customize Exception Handlers In An ADF REST DC Application?
(Doc ID 2877145.1)
Last updated on JUNE 15, 2022
Applies to:Oracle JDeveloper - Version 188.8.131.52.0 to 184.108.40.206.0 [Release 12c]
Information in this document applies to any platform.
According to unpublished
Bug 34270830 - NO ERROR DETAILS IN REST CALL RESPONSE WHEN USING REST FRAMEWORK VERSION 4
Oracle® Fusion Middleware Developing Fusion Web Applications with Oracle Application Development Framework 12c (220.127.116.11.0) - What You May Need to Know About Versioning the ADF REST Framework
starting from ADF 18.104.22.168.0, if the invoke of a REST endpoint exposed by an ADF REST DC application ends up with a 500 error, no error details are sent over and the response body will be empty.
Differently, if the invoke ends with a 400 error code, then the error details are sent over.
The change is due to the fact that sending details in 500 errors may expose to security treats, as explained in unpublished
Bug 33942808 - SERVER ERRORS FROM REST CALLS NOT CONTAINED IN RESPONSE OF MIGRATED APPLICATION
When creating an ADF DC REST application, JDeveloper does all the magic and there is no need to write any code when creating REST endpoints on top of Entity Objects persisted in a DataBase.
However, if a DataBase error occurs for whatever reason, including application's business logic (e.g. duplicate entry, custom DB errors raised from Stored Procedures), that will cause an exception (i.e. SQLException) to be raised and flow in the J2EE container as an unchecked exception, with the consequence that it will be interpreted as an internal error causing also the generation of an error response with 500 error code and without details.
This means that the REST endpoint clients will not be aware there was actually a business logic violation error instead of a true system error.
How to intercept these situations at application side and send custom 400 error response in the scenario described above?
In the specific, how to wrap DML exceptions raised from persistence layer into custom exceptions?
To view full details, sign in with your My Oracle Support account.
Don't have a My Oracle Support account? Click to get started!
In this Document