Skip to main content
1-Visitor
June 18, 2020
Question

Thing Service returns "500 Unexpected Error - Contact your system administrator for more"

  • June 18, 2020
  • 1 reply
  • 2886 views

Hi, 

we would like to call a Service, which returns a JSON, when you call it with a POST request. 

Unfortunately, we get the following response when we call the Service via Postman:

The URI we use: http://localhost:8080/Thingworx/Things/{ThingName}/Services/Get_All_Sensor_Data

The Response: 

<!DOCTYPE html>
<html>

<head>
  <title>Unexpected Error</title>
  <script>
    function clickAndDisable(link) {
              link.onclick = function(event) {
                event.preventDefault();
              }
            }
  </script>
</head>

<body>
  <div class="widget-panel widget-container widget-content" style="overflow: auto;">
    <div class="widget-content widget-image undefined" id="error_Image-1">
      <img src="/Thingworx/images/ThingworxLogo.png" alt="Errors"/>
      </div>
    </div>
    <div id="error_Panel-1">
      <p>500 Unexpected Error - Contact your system administrator for more details</p>
      <a href="/Thingworx" onclick='clickAndDisable(this);'>Back to Composer</a>
    </div>
</body>

</html>

Our current code:  (not final)
var result = {};
if(code >= 500)
{
try
{
result.message = Resources["JSONErrorResource"].GetBadRequest(
{content: {"plop": "error"}});
result.status = "200";
}
catch( err )
{
logger.error( "The following error occured. " + err );
result.status = "500";
result.message = "Some Error message here";
}
}
else
{
result.status = "200";
result.message = "ok";
}

1 reply

Community Manager
June 18, 2020

HI @DigitalFactory.

 

There are a lot of questions here:

 

  • What happens when you run the service directly in Composer?
  • What account (appKey) does the service run under when calling the Post request?
  • Can you provide a screenshot of your Post request in Postman with the headers so we have a better idea of what you're sending?

Regards.

 

--Sharon

1-Visitor
June 19, 2020

HI @slangley

thanks a lot for your answer. 
Please find the requested information below: 

When we execute the code in composer we get the following error message: 
"Error executing service Get_All_Sensor_Data. Message :: ReferenceError: "code" is not defined. - See Script Error Log for more details."

The appKey is bount to the Administrator. I know that is not best practice and just used for test purposes.

Please find a screenshot of our post man request attached.