Skip to content

Comments

Fix Storage Account connection string handling to prevent app crashes#60

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-57
Draft

Fix Storage Account connection string handling to prevent app crashes#60
Copilot wants to merge 2 commits intomainfrom
copilot/fix-57

Conversation

Copy link

Copilot AI commented Jul 15, 2025

The Azure Web App was crashing with System.InvalidOperationException when the Storage Account connection string was missing or empty. This PR fixes the issue by replacing unhandled exceptions with proper HTTP error responses and helpful guidance.

Changes Made

1. Improved Error Handling in AppController

  • Before: Threw InvalidOperationException causing app crashes
  • After: Returns proper HTTP status codes with detailed error messages
// Before: Unhandled exception
throw new InvalidOperationException("Storage account connection string is not configured.");

// After: Graceful HTTP response
return BadRequest(new { 
    error = "Storage account connection string is not configured.", 
    details = "Please configure the 'StorageAccount' connection string in app settings or appsettings.json",
    configurationKey = "ConnectionStrings:StorageAccount"
});

2. Added Development Configuration

  • Added ConnectionStrings section to appsettings.Development.json with development storage placeholder
  • Ensures consistent configuration structure across environments

Testing Results

Missing connection string: Returns HTTP 400 with helpful guidance instead of crashing
Invalid connection string: Returns HTTP 500 with connection details instead of unhandled exception
Application builds and runs successfully
No more System.InvalidOperationException crashes

Benefits

  • Improved reliability: App no longer crashes on missing configuration
  • Better debugging: Clear error messages help identify configuration issues quickly
  • Enhanced developer experience: Proper HTTP status codes and detailed guidance
  • Production readiness: Graceful handling of configuration errors

The app now handles missing storage account configuration gracefully and provides clear guidance to developers and operations teams for resolving configuration issues.

Fixes #57.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: mrsharm <68247673+mrsharm@users.noreply.github.com>
Copilot AI changed the title [WIP] App down due to missing Storage Account connection string (System.InvalidOperationException) Fix Storage Account connection string handling to prevent app crashes Jul 15, 2025
Copilot AI requested a review from mrsharm July 15, 2025 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

App down due to missing Storage Account connection string (System.InvalidOperationException)

2 participants