Skip to content

[Feedback] try catch blocks in the code samples #4461

@ArsSirek

Description

@ArsSirek

Page: /guides/functions/dynamodb-from-js-lambda/q/platform/[platform]

Feedback:
It seems to me that code samples for the Node.js are a bit frustrating on the try catch blocks

  • with this sample the error will end up in the body attribute of the response
async function getItem(){
  try {
    const data = await docClient.get(params).promise()
    return data
  } catch (err) {
    return err
  }
}

exports.handler = async (event, context) => {
  try {
    const data = await getItem()
    return { body: JSON.stringify(data) }
  } catch (err) {
    return { error: err }
  }
}

I know that it's to show the general approach only, but I would still suggest to remove the getItem as a separate function, or to add some ifs in the main function to handle the getItem returned value

Sorry if I miss something here

Metadata

Metadata

Assignees

Labels

amplify/jsIssues tied to JSp3missing info

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions