0

我正在与 Knex 合作编写一个简单的事务。我将一个对象插入一个表,然后插入一组对象。由于我在我的 API 中使用 Knex,我想知道哪个插入失败。不幸的是,错误对象仅共享此信息:

{
"length":130,
 "name":"error",
 "severity":\"ERROR\",
 "code":\"22P02\",
 "file":\"uuid.c\",
 "line":\"137\",
 "routine":\"string_to_uuid\"
}

我想知道哪个查询完全未能将正确的错误消息发送回前端。我正在使用带有 RDS 连接的 lambda 设置。

这是我的交易:

  const test = await client.transaction(async (trx) => {
    try {
      await trx<any>('schema.table')
        .insert({
          id: answers.myId,
          addition: 'some text',
        });
      const test = answers.answers.map((answer) => ({
        id: answer.id,
        my_id: answers.myId,
        offered_answer_id: answer.offered_answer_id,
        value: answer.value !== '' ? answer.value : null,
      }));
      await trx<any>('schema.table2').insert(test);
    } catch (error) {
      return error;
    }

我通过操作 uuid 来触发错误。所以错误对象在技术上是正确的,但我无法确定是哪个插入导致它使用此信息。

非常感谢任何帮助!

4

0 回答 0