[英]Mongoose ValidationError makes Express Server crashed
我已經為這個問題苦苦掙扎了很多天。
每當我發出無效的 POST 請求時,它都會拋出一個錯誤。 聽起來不錯,但是當我取消該請求時,服務器關閉了???
這是一個無效的請求。
{
"title": "Test from Postman",
"description": "Test from Postman",
"time": "2021-05-12",
"status": "abc"
}
這是我得到的錯誤。
你們可以在這里查看我的回購協議。 也許錯誤來自 mongoose 驗證
謝謝你。
我也有這個問題。 問題是我在兩個地方發現了錯誤:一個在服務器文件中,一個在應用程序文件中。 從服務器文件中刪除捕獲錯誤允許在應用程序文件中捕獲錯誤,並在應用程序文件中正確處理。
錯誤代碼:
// server file
const create = (person) => {
const request = axios.post(baseUrl, person)
return request
.then((response) => response.data)
.catch((error) => console.log(error)) // this is the problem
}
正確的代碼:
// server file
const create = (person) => {
const request = axios.post(baseUrl, person)
return request
.then((response) => response.data)
// the catch line has been removed here because the error is caught elsewhere
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.