Search code examples
getamazon-dynamodbhttp-status-code-404

Get by ID DynamoDB returns empty instead of 404


I'm doing a simple get and it works with an existent id but when I provide an unexistent id, instead of returning a 404 not found error or similar, it is returning empty data. I'm using AWS API Gateway by the way. Is this normal?

const params = {
    TableName: tableName,
    Key: { id },
};
await docClient.get(params).promise()
    .then(data => {
        response.statusCode = 200,
        response.body = JSON.stringify(data.Items);
    })
    .catch(error => {
        let newError = new Error(error.message);
        newError.code = error.code;
        response.statusCode = error.statusCode;
        response.body = JSON.stringify(newError);
    });

Solution

  • This is normal. Based on the doc, it will not throw an error when id is not found.