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

feat: update Getting-Started.md #3213

Merged
merged 2 commits into from Jul 26, 2021
Merged

Conversation

Adibla
Copy link
Contributor

@Adibla Adibla commented Jul 25, 2021

  • documentation is changed or added

With current example from Getting-started.md, I get this error and server doesn't resolve anything.

"name":"FastifyError"
"code":"FST_ERR_PROMISE_NOT_FULFILLED","statusCode":500}
"msg":"Promise may not be fulfilled with 'undefined' when statusCode is not 204"

Because "result" return undefined with an empty dataset and check only for null values doesn't avoid the exception.

@github-actions github-actions bot added the documentation Improvements or additions to documentation label Jul 25, 2021
@@ -176,15 +176,15 @@ async function routes (fastify, options) {

fastify.get('/animals', async (request, reply) => {
const result = await collection.find().toArray()
if (result.length === 0) {
if (result?.length) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fastify supports node.js 10 and 12 that does not support this syntax by default so it would be better to keep the old check

Would you mind targeting the next branch instead?

Copy link
Contributor Author

@Adibla Adibla Jul 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your feedback. Could I mantain "main" branch replacing
if(result?.length) with if(!result || result && !result.length) ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

collection.find().toArray() must return Array even if no document exist. I think it do not need any change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good, thank you. I rolled back this line.

@climba03003
Copy link
Member

Oops, it cause by the recent update of fastify-mongo. The mongo native driver changed the behavior for not found. it changed from null to undefined when document is not exist.

@Adibla Adibla changed the base branch from main to next July 25, 2021 17:22
@Adibla Adibla changed the base branch from next to main July 25, 2021 17:23
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina merged commit 1cfa32e into fastify:main Jul 26, 2021
This was referenced Aug 2, 2021
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants