Http Status Code 狀態碼 4xx: Client error responses 使用者錯誤
Http Status Code 狀態碼 4xx: Client error responses 使用者錯誤
frontend messed up
4xx
這部分的狀態碼在使用者操作或傳遞參數發生錯誤時才會回傳
400 Bad Request
或 422 Unprocessable Entity
差異
400 參數沒有傳送
例如使用者資料網址是 http://user.com/user/<user_id>
,但發出去的請求是 http://user.com/user/
沒有包含任何 <user_id>
,所以會回傳 400 Bad Request
422 參數正確傳送但格式邏輯不對
例如使用者資料網址是 http://user.com/user/<user_id>
,使用者 <user_id>
格式是整數,所以正確請求應為 http://user.com/user/123
但發出去的請求是 http://user.com/user/abc
網址中 <user_id>
格式是錯誤的,所以會回傳 422 Unprocessable Entity
Reference
- Which HTTP code is best suited for validation errors: 400 or 422? - Quora
- What Is HTTP 422 And Why You Should Use It? - Paweł Pluta
- API Error 422: Unprocessable Entity - bonsai
- 422 Unprocessable Entity
- 422 Unprocessable Entity Explained - KeyCDN Support
- rest - 400 vs 422 response to POST of data - Stack Overflow
- Paypal API responses
- How to Fix a 400 Bad Request Error [Causes & Fixes]
- How to Fix the 400 Bad Request Error
參考資料
最後修改 April 29, 2021