Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tech debt | Null handling for db queries in activity methods #23

Open
Behold3th opened this issue Mar 24, 2022 · 0 comments
Open

Tech debt | Null handling for db queries in activity methods #23

Behold3th opened this issue Mar 24, 2022 · 0 comments

Comments

@Behold3th
Copy link
Collaborator

Behold3th commented Mar 24, 2022

Currently, we perform validation on the status of a bounty by checking for the correct status in our validation module. If we don't find the correct status, we serve an error message to the user detailing that the bounty is not in the expected status for that activity.

e.g,

    if (dbBountyResult.status && dbBountyResult.status !== BountyStatus.open) {
        throw new ValidationError(
            `The bounty id you have selected is in status ${dbBountyResult.status}\n` +
            `Currently, only bounties with status ${BountyStatus.open} can be applied for.\n` +
            `Please reach out to your favorite Bounty Board representative with any questions!`
            );
    }

By the time the bounty has made it to the activity, a few ms have passed. It's possible, though very very improbable, that the bounty status has been updated in that time by the web client. Thus in the activity, we add status as a field to our queries, so that a null result is returned if the bounty is not longer in the state we expect. This causes a Runtime exception, and the user is served a "Sorry, something isn't working and our devs are looking into it" error message.

e.g,

const getDbHandler = async (request: SubmitRequest): Promise<{dbBountyResult: BountyCollection, bountyChannel: string}> => {
    const db: Db = await MongoDbUtils.connect('bountyboard');
	const bountyCollection = db.collection('bounties');
    const customerCollection = db.collection('customers');

	const dbBountyResult: BountyCollection = await bountyCollection.findOne({
		_id: new mongo.ObjectId(request.bountyId),
		status: BountyStatus.in_progress,
	});

A better UX would be to serve a validation exception (as that is the actual cause of why the activity can't proceed). This needs to be implemented for all of our activities.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant