getPolicy method

Future<PolicyEntry> getPolicy(
  1. String policyId
)

Requests a policy entry (matching the policyId) from the S3I-Directory.

Throws a NetworkAuthenticationException if AuthenticationManager.getAccessToken fails. Throws a SocketException if no internet connection is available. Throws a NetworkResponseException if the received status code is not 200. Throws a ResponseParsingException if something went wrong during the parsing to the directory objects.

Implementation

Future<PolicyEntry> getPolicy(String policyId) async {
  final Response response = await getDirectory('/policies/$policyId');
  if (response.statusCode != 200) throw NetworkResponseException(response);
  try {
    return PolicyEntry.fromJson(
        jsonDecode(utf8.decode(response.bodyBytes)) as Map<String, dynamic>);
  } on FormatException catch (e) {
    throw ResponseParsingException(e);
  } on InvalidJsonSchemaException catch (e) {
    throw ResponseParsingException(e);
  } on TypeError catch (e) {
    throw ResponseParsingException(
        InvalidJsonSchemaException(e.stackTrace.toString(), response.body));
  }
}