Hiện tại, các nhà phát triển đã có thể sử dụng rộng rãi tiện ích bổ sung của Google Lớp học! Vui lòng xem
tài liệu về tiện ích bổ sung để biết thêm thông tin.
Cấu trúc lỗi API Google Lớp học
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Classroom API trả về thông tin lỗi có thể giúp nhà phát triển gỡ lỗi và cung cấp thông tin hữu ích, thiết thực cho người dùng cuối. Hướng dẫn này giải thích cách phân tích cú pháp thông tin lỗi do API trả về.
Classroom API trả về 2 cấp độ thông tin lỗi:
- Mã lỗi HTTP trong tiêu đề.
- Một đối tượng trong nội dung phản hồi có thông tin chi tiết bổ sung.
Cấu trúc thông báo lỗi
Các lỗi được trả về trong phần nội dung phản hồi bao gồm các trường sau:
code
: Mã lỗi HTTP bằng số. Ví dụ: 403
.
message
: Thông tin chi tiết khác về lỗi. Khi có sẵn, thông báo lỗi sẽ được thêm tiền tố @
và một loại lỗi cụ thể. Ví dụ: @ClassroomApiDisabled
status
: Trạng thái yêu cầu HTTP. Ví dụ: PERMISSION_DENIED
hoặc NOT_FOUND
.
Nếu một yêu cầu không thành công do lỗi ClassroomApiDisabled
, thì phản hồi sẽ là:
{
"error": {
"code": 403,
"message": "@ClassroomApiDisabled The user is not permitted to access the Classroom API.",
"status": "PERMISSION_DENIED"
}
}
Bạn có thể sử dụng nội dung phản hồi để gỡ lỗi nguyên nhân gây ra lỗi và cung cấp thông tin hữu ích cho người dùng. Thêm một khoảng trắng ở cuối khi kiểm tra một thông báo lỗi cụ thể để tránh trùng khớp với các giá trị khác bắt đầu bằng cùng một chuỗi. Trong ví dụ về lỗi được cung cấp, bạn có thể kiểm tra xem trường thông báo có bắt đầu bằng "@ClassroomApiDisabled "
hay không để trình bày thông tin phù hợp cho người dùng.
Tham khảo trang Các lỗi thường gặp để biết thông tin về một số lỗi mà Classroom API có thể trả về.
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-08-29 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-08-29 UTC."],[],[],null,["# Google Classroom API error structure\n\nThe Classroom API returns error information that can help developers\ndebug issues and provide helpful, actionable information to end users. This\nguide explains how to parse error information returned from the API.\n\nThe Classroom API returns two levels of error information:\n\n- HTTP error code in the header.\n- An object in the response body with additional details.\n\nError message structure\n-----------------------\n\nErrors returned in the response body include the following fields:\n\n- `code`: The numerical HTTP error code. For example, `403`.\n- `message`: Additional details about the error. When available, the error message is prepended with `@` and a specific error type. For example, `@ClassroomApiDisabled`.\n- `status`: The HTTP request status. For example, `PERMISSION_DENIED` or `NOT_FOUND`.\n\nIf a request failed with a [`ClassroomApiDisabled`](/workspace/classroom/troubleshooting/common-errors#classroom-api-disabled) error, the response would\nbe: \n\n {\n \"error\": {\n \"code\": 403,\n \"message\": \"@ClassroomApiDisabled The user is not permitted to access the Classroom API.\",\n \"status\": \"PERMISSION_DENIED\"\n }\n }\n\nYou can use the response body to help you debug the cause of the error and\nprovide helpful information to users. Include a trailing space when checking\nfor a specific error message to avoid matching other values that start with\nthe same string. In the provided error example, you can check if the message\nfield begins with `\"@ClassroomApiDisabled \"` to present appropriate information\nto users.\n\nReference the [Common errors](/workspace/classroom/troubleshooting/common-errors) page for information on some errors that\ncan be returned by the Classroom API."]]