You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the coffee machine tutorial, there is the following code:
thing.setPropertyReadHandler('availableResourceLevel',(options)=>{// Check if uriVariables are providedif(options&&typeofoptions==='object'&&'uriVariables'inoptions){consturiVariables: any=options['uriVariables'];if('id'inuriVariables){returnthing.readProperty('allAvailableResources').then((resources)=>{constid=uriVariables['id'];returnnewPromise((resolve,reject)=>{resolve(resources[id]);});});}}returnnewPromise((resolve,reject)=>{resolve('Please specify id variable as uriVariables.');});});
The first part is completely fine but the last lines on returning a Promise will actually make the Client think that everything is OK since in HTTP it would map to 200 status code. The correct way would be to return an HTTP 400 Bad Request but this is not possible at the moment (See this issue on node-wot: eclipse-thingweb/node-wot#140). For now, this should at least be a reject instead of a resolve.
I had that in the very beginning since it also seems more logical to me. However, I have changed it resolve + error message, since using reject doesn't give any error to a client and the client just infinitely awaits a response. And only on the producer Thing side, the error says (node:2155) UnhandledPromiseRejectionWarning: Please specify id variable as uriVariables. So, I guess there are some additional promise rejection mechanisms missing.
In the coffee machine tutorial, there is the following code:
The first part is completely fine but the last lines on returning a Promise will actually make the Client think that everything is OK since in HTTP it would map to 200 status code. The correct way would be to return an HTTP 400 Bad Request but this is not possible at the moment (See this issue on node-wot: eclipse-thingweb/node-wot#140). For now, this should at least be a reject instead of a resolve.
Could you correct this @fatadel ?
The text was updated successfully, but these errors were encountered: