Handling API Errors

The Classroom API returns two levels of error information:

  • HTTP error codes and messages in the header
  • A JSON object in the response body with additional details

You can use the response object for debugging. In some cases, the response may contain additional error details. You can use these details to disambiguate the cause of the error and provide information to users or direct them to take appropriate action.

Error Message Structure

When available, additional error details are included in the message field of the error formatted as a @ followed by an error code.

For example, if a request failed with a ClassroomApiDisabled error, the JSON response would be:

{
  "error": {
    "code": 403,
      "message": "@ClassroomApiDisabled The user is not permitted to access the Classroom API.",
      "errors": [
        {
          "message": "@ClassroomApiDisabled The user is not permitted to access the Classroom API.",
          "domain": "global",
          "reason": "forbidden"
        }
      ],
      "status": "PERMISSION_DENIED"
  }
}

You can check that the message field starts with "@ClassroomApiDisabled " and present an appropriate prompt to users. Include a trailing space when checking for an error code to avoid matching other values that start with the same string.