Scripted REST API not processing status code 500

deepak50
Tera Contributor

Hi,
I have created a scripted REST api which sends status code 500 in case of error.
But when some response is sent with status code 500 , Response body does not show the correct format , instead it shows on html saying "Instance Unavailable"

var processError = new sn_ws_err.ServiceError();
processError.setStatus(500);
return processError;
           
In response:
Status code
500 Internal Server Error
Response Body:
"<!DOCTYPE html>\n<html>
<head>
.
.
<title>Instance Unavailable</title>
.
.
< Service Interruption - This instance is unavailable

.

If service does not restore promptly, please open a Case in the ServiceNow HI Service Portal or contact Technical Support
.
.
"
-----------------------------------------------------------------------------------------------------------------------------------------------

If I change status code to 400 , I get correct response with response body.

Status code
400 Bad Request
Response Body:
{
  "error": {
    "message": "",
    "detail": ""
  },
  "status": "failure"
}

Is this issue because of Instance or API, Please let me know how to fix this.

Thanks
Deepak

2 REPLIES 2

BALAJI40
Mega Sage

Hi Deepak,

Just give a try the custom error code as defined in the screenshot (define error message and detail as well) because for 400 error default message defined OOB.

find_real_file.png

deepak50
Tera Contributor

Hi Balaji,

I tried this setMessage, setDetails but getting same error, It is working if I change status code from 500 to 400 or 550.

Thanks

Deepak