Error handling

The zeuz API returns custom error codes in the error field of the JSON response. Handle response data directly in your functions.

zeuz API endpoints return HTTP response status codes. See HTTP status code definitions for details.

Check for invalid and expired sessions

It is important to check for invalid and expired login sessions in your code, and handle these events appropriately. Make sure you follow the login flow again if you receive an invalid or expired session response in the error field.

You can use the following code to check the error field for invalid_session and session_expired and retry the login if either error is present.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
// Check whether the error field is set
auto error = response_json["Error"].asString();
if (!error.empty()) {
   if (error.rfind("invalid_session", 0) == 0 ||
       error.rfind("session_expired", 0) == 0) {
       // Log in again and retry the request
   } else {
       throw std::string("could not complete request (" + response + ")");
   }
}


2021-aug-3 Page added with editorial review.


Last edited on: September 23, 2021 (a8f4a430)