Skip to content

Should we avoid using reject when no data is found? #207

@r03ert0

Description

@r03ert0

There is a pattern being used in db.js, for example in queryAllUsers and queryUser, where an error is generated if no entries in the DB match the query. For example:

db.get('users').find(query)
    .then((users) => {
        if(users) {
            resolve(users);
        } else {
            reject({message: 'error find all users', result: users});
        }
    })
    .catch(reject);

Wouldn't it be more appropriate to just return an empty object/array instead of sending a reject, and keep reject only when there's an error? Like:

db.get('users').find(query)
    .then(resolve)
    .catch(reject);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions