getProjectBySlug method

Future<ProjectListItem> getProjectBySlug(
  1. String slug
)

Get a project by its slug

Implementation

Future<ProjectListItem> getProjectBySlug(String slug) async {
  final url = Uri.parse('$baseUrl/projects/by-slug/$slug');
  final headers = await _authHeaders();

  final response = await _getWithRetry(url, headers);

  if (response.statusCode == 401) {
    throw Exception(
      'Authentication failed. Please run "ulink login" to re-authenticate.',
    );
  } else if (response.statusCode == 403) {
    throw Exception(
      'Access forbidden. You may not have permission to access this project.',
    );
  } else if (response.statusCode == 404) {
    throw Exception(
      'Project not found. Please check the project slug.',
    );
  } else if (response.statusCode != 200) {
    throw Exception(
      'Failed to fetch project: ${response.statusCode} ${response.body}',
    );
  }

  final json = jsonDecode(response.body) as Map<String, dynamic>;
  return ProjectListItem.fromJson(json);
}