cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

Writing Custom Thingworx Service 400 - 500 Level Error Return Codes

SG_9149098
5-Regular Member

Writing Custom Thingworx Service 400 - 500 Level Error Return Codes

Is it possible to write a Thingworx service in Javascript to return custom 400 - 500 level error codes for when the service is being called via REST?  Or does REST calls to a custom Thingworx service only return the standard defined set of response codes, including error codes?

7 REPLIES 7
anarwal
12-Amethyst
(To:SG_9149098)

Hi @SG_9149098 ,

 

In ThingWorx javascript service you can write your try/catch block and write your custom logs entries as per wish .. but the type of error/exception thrown would generally follow standard rules of JS.
 
Note : If my response has answered your question, please mark as Accepted Solution, for the benefit of others who may have the same question.
SG_9149098
5-Regular Member
(To:anarwal)

Thanks for the response anarwal.  Do you happen to have an example of returning 400 or 500 level error codes in Thingworx javascript?  It seems javascript functionality in Thingworx is a little more restricted versus some of the javascript functionality available outside of Thingworx.

SG_9149098
5-Regular Member
(To:anarwal)

So I'm getting the impression that the Thingworx product is incapable of allowing a developer to define and return specific HTTP response status codes back the the caller like what is capable on other platforms.  The caller will only receive a 200 level response code or an error message.  Defining specific 400 or 500 level response codes in Thingworx services is not possible on the Thingworx platform.  Is this a true statement?

cbaldwin
13-Aquamarine
(To:SG_9149098)

You are correct.  The JS services will return 200 on success or 500 upon error.  The message you use in the error output is what will be passed in the 500 result.  You do not have control over the HTTP response codes as a script developer.

SG_9149098
5-Regular Member
(To:cbaldwin)

I will try it out.  Thanks

slangley
23-Emerald II
(To:SG_9149098)

Hi @SG_9149098.

 

If you feel your question has been answered (even if it was not the answer you wanted), please mark the appropriate response as the Accepted Solution for the benefit of others with the same question.

 

Regards.

 

--Sharon

slangley
23-Emerald II
(To:slangley)

Hi @SG_9149098.

 

If you feel your question has been answered, please mark the appropriate response as the Accepted Solution for the benefit of others with the same question.

 

Regards.

 

--Sharon

Top Tags