From 3904e0bce580aaba32b14476cd3bf79e30379818 Mon Sep 17 00:00:00 2001 From: 6d486f49 Date: Thu, 18 Jun 2026 18:47:42 -0400 Subject: [PATCH] Server now silently fails with no PostgreSQL --- Chrono/Server/Controllers/NotesController.cs | 40 ++++++++++++++------ Chrono/Server/Program.cs | 21 ++++++++-- Chrono/Web/Web.csproj | 1 + Chrono/Web/wwwroot/index.html | 2 +- 4 files changed, 48 insertions(+), 16 deletions(-) diff --git a/Chrono/Server/Controllers/NotesController.cs b/Chrono/Server/Controllers/NotesController.cs index bcb8860..212e4fa 100644 --- a/Chrono/Server/Controllers/NotesController.cs +++ b/Chrono/Server/Controllers/NotesController.cs @@ -18,28 +18,44 @@ public class NotesController : ControllerBase [HttpGet("{cardName}")] public async Task> GetNote(string cardName) { - var note = await _context.CardNotes.FindAsync(cardName); - if (note == null) + try { + var note = await _context.CardNotes.FindAsync(cardName); + if (note == null) + { + return Ok(new CardNote { CardName = cardName, Note = "" }); + } + return Ok(note); + } + catch (Exception ex) + { + Console.WriteLine($"[WARNING] Could not retrieve note from database: {ex.Message}"); return Ok(new CardNote { CardName = cardName, Note = "" }); } - return Ok(note); } [HttpPost] public async Task> UpdateNote(CardNote note) { - var existing = await _context.CardNotes.FindAsync(note.CardName); - if (existing == null) + try { - _context.CardNotes.Add(note); - } - else - { - existing.Note = note.Note; - } + var existing = await _context.CardNotes.FindAsync(note.CardName); + if (existing == null) + { + _context.CardNotes.Add(note); + } + else + { + existing.Note = note.Note; + } - await _context.SaveChangesAsync(); + await _context.SaveChangesAsync(); + } + catch (Exception ex) + { + Console.WriteLine($"[WARNING] Could not save note to database: {ex.Message}"); + } + return Ok(note); } } diff --git a/Chrono/Server/Program.cs b/Chrono/Server/Program.cs index 70335a6..e795637 100644 --- a/Chrono/Server/Program.cs +++ b/Chrono/Server/Program.cs @@ -10,15 +10,30 @@ builder.Services.AddRazorPages(); var connectionString = builder.Configuration.GetConnectionString("DefaultConnection"); builder.Services.AddDbContext(options => - options.UseNpgsql(connectionString)); +{ + if (!string.IsNullOrEmpty(connectionString)) + { + options.UseNpgsql(connectionString); + } +}); var app = builder.Build(); // Apply migrations using (var scope = app.Services.CreateScope()) { - var db = scope.ServiceProvider.GetRequiredService(); - db.Database.Migrate(); + try + { + var db = scope.ServiceProvider.GetRequiredService(); + if (!string.IsNullOrEmpty(connectionString)) + { + db.Database.Migrate(); + } + } + catch (Exception ex) + { + Console.WriteLine($"[WARNING] Database migration failed: {ex.Message}. The application will continue without a database connection."); + } } // Configure the HTTP request pipeline. diff --git a/Chrono/Web/Web.csproj b/Chrono/Web/Web.csproj index 7660786..14d424b 100644 --- a/Chrono/Web/Web.csproj +++ b/Chrono/Web/Web.csproj @@ -5,6 +5,7 @@ enable enable false + false diff --git a/Chrono/Web/wwwroot/index.html b/Chrono/Web/wwwroot/index.html index 3488404..0f6266a 100644 --- a/Chrono/Web/wwwroot/index.html +++ b/Chrono/Web/wwwroot/index.html @@ -11,7 +11,7 @@ - +