Khi xảy ra lỗi, API trả về body JSON theo định dạng chuẩn:
{"status":<code>,"error":"<reason>","message":"<msg>"}
trong đó <reason> là reason phrase chuẩn của mã.
Bảng reason phrase:
| Code | Reason |
|---|---|
| 400 | Bad Request |
| 401 | Unauthorized |
| 403 | Forbidden |
| 404 | Not Found |
| 409 | Conflict |
| 422 | Unprocessable Entity |
| 500 | Internal Server Error |
In ra đúng một dòng JSON (không khoảng trắng thừa, đúng thứ tự khóa: status, error, message).
Input:
404
User khong ton tai
Output: {"status":404,"error":"Not Found","message":"User khong ton tai"}
Dòng 1: mã trạng thái lỗi. Dòng 2: thông điệp (message), có thể chứa khoảng trắng.
code ∈ bảng. message dài ≤ 100 ký tự, không chứa dấu nháy kép " hay backslash.
Một dòng JSON {"status":<code>,"error":"<reason>","message":"<msg>"}.
Ví dụ:
Đầu vào:
404
User khong ton tai
Đầu ra:
{"status":404,"error":"Not Found","message":"User khong ton tai"}Giải thích:
Đang tải editor...