deleteOrg method

  1. @override
Future<void> deleteOrg(
  1. String orgId
)
override

Deletes the the org with the given org id

Implementation

@override
Future<void> deleteOrg(String orgId) async {
  final operation = _amplifyApi.query<String>(
    request: GraphQLRequest(
      document: '''
        mutation DeleteOrg(\$orgID: ID!) {
          deleteOrg(orgID: \$orgID)
        }
      ''',
      variables: {
        'orgID': orgId,
      },
    ),
  );
  final response = await operation.response.onError((e, stackTrace) {
    _logger.severe(
      'Exception when invoking service call to '
      'delete org with org id "$orgId": $e',
    );

    throw OrgServiceError(
      message: 'Failed to delete org with id: $orgId',
      innerException: e is Exception ? e : Exception(e),
      innerStackTrace: stackTrace,
    );
  });

  if (response.hasErrors) {
    final errorPayload = jsonEncode(response.errors);
    _logger.severe('Failed to delete org: $errorPayload');

    if (response.errors.any(
      (error) => error.message.contains(
        'not associated with the given org',
      ),
    )) {
      throw OrgDoesNotExistError(orgId: orgId);
    } else {
      throw OrgDeleteError(orgId: orgId);
    }
  }

  final data = response.data;
  _logger.finest('Org deleted: $data');
}