2 Replies Latest reply on Apr 27, 2016 7:57 AM by david.pye

    Returning error object from an ORDS 3.0 POST Call


      We are using ORDS 3.0 and have a POST call that accepts a JSON object in the body. This object contains an array of field names and values as entered in our frontend application.


      The PL/SQL within our POST call validates the supplied values and if there are any validation errors we need to return a 400 HTTP status code in the response header and a JSON object in the response body. This JSON object contains an array listing all fields with a validation error and all validation errors for each such field.


      So far, the only method we have found to let us return such a JSON object is to:


      i. Save the errors to a database table within the POST PL/SQL exception handler.


      ii. Set X-APEX-FORWARD in the POST PL/SQL exception handling to re-direct to a GET call to retrieve the validation errors. This GET call can return the errors in the JSON object format that we require.


      The problem with this solution is that the HTTP status code returned to the frontend client is the 200 from the GET (i.e. it has successfully retrieved the errors) rather than the 400 from the POST (indicating that the validation has failed).


      So, does anyone know how to either:


      i. Return a JSON object directly from the POST call (rather than via a GET specified in X-APEX-FORWARD)?


      ii. Force our GET that retrieves the errors to still return the error object but also return a 400 HTTP status code?


      Thanks in advance!