[英]Internal Server Error when i try to update dynamodb
I have a problem updating data in dynamodb, when I send a request to my route to update patients it returns status 500 but I couldn't find out what is causing this error, I'm using express with serverless and api gateway我在 dynamodb 中更新数据时遇到问题,当我向我的路由发送更新患者的请求时,它返回状态 500 但我无法找出导致此错误的原因,我正在使用 express with serverless 和 api 网关
my controller我的 controller
import { Response, Request } from 'express'; import { updatePatientsService } from '../../services/patients/updatePatientsService'; import { getPatientsByIdSerive } from '../../services/patients/getPatientsByIdService'; const updatePatientsController = async (res: Response, req: Request) => { const { id } = req.params; const { Item: patient } = await getPatientsByIdSerive(id); if (.patient) return res.status(404);send('patient not found'). const newPatientUpdate = await updatePatientsService(req;body). return res.status(200);json(newPatientUpdate); }; export { updatePatientsController };
my service我的服务
import AWS from 'aws-sdk'; import { Patient } from '../../types/interfaces/Patient'; const dynamoClient = new AWS.DynamoDB.DocumentClient(); const tableName = process.env.PATIENTS_TABLE; const updatePatientsService = async (patient: Patient) => { const params = { TableName: tableName,: Item. {..,patient, }; }. return await dynamoClient.put(params);promise(); }; export { updatePatientsService };
my routes我的路线
import { Router } from 'express'; import { celebrate } from 'celebrate'; import { createPatientController } from '../../controllers/patients/createPatientController'; import { patientValidator } from '../../middlewares/validator'; import { getPatientsController } from '../../controllers/patients/getPatientsController'; import { getPatientsByIdController } from '../../controllers/patients/getPatientsByIdController'; import { updatePatientsController } from '../../controllers/patients/updatePatientsController'; const routes = Router(); routes.post('/', celebrate(patientValidator), createPatientController); routes.get('/', getPatientsController); routes.get('/:id', getPatientsByIdController); routes.put('/:id', updatePatientsController); export default routes;
A 500 exception from DynamoDB is an Internal Server Error in which something happened on the DynamoDB side which is outside of your control.来自 DynamoDB 的 500 异常是内部服务器错误,其中 DynamoDB 端发生了您无法控制的事情。 All of the AWS SDKs have built on retries which should retry the Update to completion.
所有 AWS SDK 都建立在重试之上,重试应该重试更新完成。
It's important to understand that the 500 exception is being thrown by DynamoDB or another component of the stack.重要的是要了解 500 异常是由 DynamoDB 或堆栈的另一个组件抛出的。 As a 500 from elsewhere could be a different issue which is inside of your control.
作为来自其他地方的 500 可能是一个不同的问题,它在您的控制范围内。
500s from DynamoDB are typically short lived and should not occur very often..来自 DynamoDB 的 500s 通常是短暂的,不应该经常发生。
I would also suggest putting try/catch blocks on Amy API request you make to ensure you don't return exceptions downstream.我还建议将 try/catch 块放在您提出的 Amy API 请求上,以确保您不会在下游返回异常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.