Dsn.parse constructor

Dsn.parse(
  1. String dsn
)

Parses a DSN String to a Dsn object

Implementation

factory Dsn.parse(String dsn) {
  final uri = Uri.parse(dsn);
  final userInfo = uri.userInfo.split(':');

  if (uri.pathSegments.isEmpty) {
    throw ArgumentError(
      'Project ID not found in the URI path of the DSN URI: $dsn',
    );
  }

  return Dsn(
    publicKey: userInfo[0],
    secretKey: userInfo.length >= 2 ? userInfo[1] : null,
    projectId: uri.pathSegments.last,
    uri: uri,
  );
}