getTokenExpirationDateFromResponse method

DateTime? getTokenExpirationDateFromResponse(
  1. RestResponse response
)

Implementation

DateTime? getTokenExpirationDateFromResponse(RestResponse response) {
  Map<String, String>? headers = response.getHeaders();

  if (headers == null || headers.isEmpty) return null;

  if (headers.containsKey(HEADER_TOKEN_EXPIRATION_DATE.toLowerCase())) {
    try {
      DateFormat format = DateFormat(TOKEN_EXPIRATION_DATE_FORMAT);
      DateTime expirationDate = format.parse(
          headers[HEADER_TOKEN_EXPIRATION_DATE.toLowerCase()]!, true);
      return expirationDate;
    } catch (e) {
      log("Error while parsing 'CB-Token-ExpirationDate', error: $e");
      return null;
    }
  } else {
    return null;
  }
}