Skip to content

Commit

Permalink
Merge pull request #45 from Purdue-ACM-SIGAPP/secret-missing-error
Browse files Browse the repository at this point in the history
Add error message if user secret is missing
  • Loading branch information
ColinWu0403 authored Nov 14, 2024
2 parents 4aaa4c1 + f21ec0a commit e9aaec2
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Services/MongoDbService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,24 @@ public class MongoDbService
public MongoDbService(IConfiguration configuration)
{
_configuration = configuration;

var connectionString = _configuration.GetConnectionString("DbConnection");
var databaseName = _configuration.GetConnectionString("DatabaseName");

if (connectionString == null)
{
Console.WriteLine("\x1b[38;2;255;000;000m");
Console.WriteLine("Error: connection URL secret is missing.");
Console.WriteLine("Run the command in the Discord starting with");
Console.WriteLine("'dotnet user-secrets', then try again.");

Environment.Exit(1);
}

Console.WriteLine("connection information:");
Console.WriteLine(connectionString);
Console.WriteLine(databaseName);

var mongoUrl = MongoUrl.Create(connectionString);
var mongoClient = new MongoClient(mongoUrl);
_database = mongoClient.GetDatabase(databaseName);
Expand Down

0 comments on commit e9aaec2

Please sign in to comment.