Not getting correct error message for Scripted REST API

Mahesh Bachhav
Kilo Expert

I have scripted REST API that accepts request body in JSON format and the maximum size is 10 MB(default).

Partial REST API Code - 

(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
    var requestBody = request.body;
    var requestString = requestBody.dataString;
    
    .
    .
    .
    .
    .
    .
})(request, response);

If the size of request body is more than 10 MB then ServiceNow returns 500 Internal Server Error response with the below error message - 

find_real_file.png

I am expecting the below error message from the API response. How to get the below error message?

find_real_file.png

3 REPLIES 3

Marc Mouries
ServiceNow Employee
ServiceNow Employee

To handle a response data larger than 10 MB you need to use a Data Stream

https://docs.servicenow.com/bundle/rome-servicenow-platform/page/administer/integrationhub/tasks/use-data-stream-in-flow.html

Tony Chatfield1
Kilo Patron

Hi, I have not found any SNC reference to configuring custom response for excessive payload size, can you clarify where this is configured?
I am guessing but if it is in the scripted REST API and if your file size exceeds the set limits, then I would not expect the payload to get as far as your scripted REST API so could not generate the custom message.

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi Mahesh,

Is there a try-catch block to catch errors in code?

getMessage() is a function to get message translation. An error may be occurring somewhere in the code and not being able to get a message to be returned.