【发布时间】:2020-07-30 14:08:26
【问题描述】:
假设我有一个存储在我的数据库中的数据列表。那么当用户输入了无效的semesterId 或无效的classId 或无效的dayofWeek 时,如何显示错误信息和API 响应以使我的后端不会崩溃?
以下是发出的请求,其中包含无效的 termId 和错误的 dayofWeek
//SEND REQUEST
GET http://localhost:3000/basic/result?semesterId=2020100001&classId=4110000001&dayofWeek=9 HTTP/1.1
Content-Type: application/json
这是我的 API
app.get('/basic/result', function (req, res, next) {
const { classId, semesterId, dayofWeek } = req.query;
//send the function to the backend
database.getDayLecture(classId, semesterId, dayofWeek, (error, result) => {
const sortResult = backend.minHalls(result);
if (error) {
return next(error);
}else {
return res.json({
result: sortResult,
});
}
});
});
谁能帮我解决这个问题?谢谢!
【问题讨论】:
标签: javascript api httprequest