Skip to content

[Coffee Machine] Wrong use of resolve in uriVariables #19

@egekorkan

Description

@egekorkan

In the coffee machine tutorial, there is the following code:

    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: eclipse-thingweb/node-wot#140). For now, this should at least be a reject instead of a resolve.

Could you correct this @fatadel ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions