eclipse-thingweb / eclipse-thingweb/website

[Coffee Machine] Wrong use of resolve in uriVariables

Open
#19 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
4
Forks
12
Avg merge
8h 17m
Merged PRs (30d)
8

Description

In the coffee machine tutorial, there is the following code:
```js
thing.setPropertyReadHandler('availableResourceLevel', (options) => {

// Check if uriVariables are provided
if (options && typeof options === 'object' && 'uriVariables' in options) {
const uriVariables: any = options['uriVariables'];
if ('id' in uriVariables) {
return thing.readProperty('allAvailableResources').then((resources) => {
const id = uriVariables['id'];
return new Promise((resolve, reject) => {
resolve(resources[id]);
});
});
}
}
return new Promise((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: https://github.com/eclipse/thingweb.node-wot/issues/140). **For now**, this should at least be a reject instead of a resolve.

Could you correct this @fatadel ?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.