Skip to content

Commit

Permalink
RavenDB-23556: Improve connection string validation and error handlin…
Browse files Browse the repository at this point in the history
…g in `OngoingTasksHandler`
  • Loading branch information
ArieSLV committed Jan 30, 2025
1 parent 35749d1 commit 31e07ff
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ public override async ValueTask ExecuteAsync()

var connectionStringName = RequestHandler.GetStringQueryString("connectionStringName", false);
var typeString = RequestHandler.GetStringQueryString("type", false);
if (Enum.TryParse(typeString, ignoreCase: true, out ConnectionStringType connectionStringType) == false && typeString != null)
throw new NotSupportedException($"Unknown connection string type: {connectionStringType}");

await RequestHandler.ServerStore.EnsureNotPassiveAsync();
RequestHandler.HttpContext.Response.StatusCode = (int)HttpStatusCode.OK;
Expand All @@ -42,9 +40,20 @@ public override async ValueTask ExecuteAsync()
using (context.OpenReadTransaction())
using (var rawRecord = RequestHandler.ServerStore.Cluster.ReadRawDatabaseRecord(context, RequestHandler.DatabaseName))
{
connectionStrings = string.IsNullOrWhiteSpace(connectionStringName)
? rawRecord.GetConnectionString(connectionStringName, connectionStringType)
: rawRecord.GetConnectionStrings();
if (connectionStringName != null)
{
if (string.IsNullOrWhiteSpace(connectionStringName))
throw new BadRequestException($"'{nameof(connectionStringName)}' must have a non empty value");

if (Enum.TryParse(typeString, ignoreCase: true, out ConnectionStringType connectionStringType) == false)
throw new BadRequestException($"Unknown connection string type: {typeString}");

connectionStrings = rawRecord.GetConnectionString(connectionStringName, connectionStringType);
}
else
{
connectionStrings = rawRecord.GetConnectionStrings();
}
}

await using (var writer = new AsyncBlittableJsonTextWriter(context, RequestHandler.ResponseBodyStream()))
Expand Down

0 comments on commit 31e07ff

Please sign in to comment.