Получение ответа об ошибке = null от шлюза API и DynamoDb

{ошибка: не удается прочитать свойство playerId, равное нулю}

Я создал лямбда-функцию списка

который передается в playerId. Этот playerId используется так.

export const main = handler(async (event, context) => { 
const data = JSON.parse(event.body);
const params = {
  TableName: process.env.teamsTable,
  ExpressionAttributeValues : {
    ':playerId' : { S: data.playerId }
  },
  FilterExpression: "contains (players, :playerId)"
};
try {
  const result = await dynamoDb.scan(params);
  if (!result.Items) {
    throw new Error("Teams not found.");
  }

  return {
    status: 200,
    body: result.Items,
  };
} catch (e) {
return {
  statusCode: 500,
  body: JSON.stringify({ error: e.message }),
};}});

Я протестировал его локально с помощью бессерверных моков, и он работает. Создайте вызов, чтобы использовать его в FE и получить следующую ошибку: {error: Cannot read property 'playerId' of null} error: Cannot read property 'playerId' of null, also hit it through API gateway and hit the same. вызов frontEnd -

  const endpoint = "/teams";
  console.log(playerId);
  try {
    const response = await API.get(amplifyAPIName, endpoint, {
      body: playerId
    });
    return response;
  } catch {
    return [];
  }
}

помощь


person Fenton Haslam    schedule 11.03.2021    source источник
comment
шлюз API определяется с помощью Lambda или Lambda_Proxy? мы можем проверить / изменить этот параметр здесь, для вашего кода вам понадобится Lambda_Proxy.   -  person Balu Vyamajala    schedule 11.03.2021
comment
Это из-за помещения тела в метод GET?   -  person Zem    schedule 12.03.2021
comment
Да! Ааа спасибо!   -  person Fenton Haslam    schedule 12.03.2021
comment
Удачи!   -  person Zem    schedule 12.03.2021


Ответы (1)


Ответ: Я использовал метод get вместо post. Я передаю playerId как выражение фильтра в aws. Изменив его на сообщение, я смог получить свои результаты.

person Fenton Haslam    schedule 12.03.2021