Handle URI parsing exception

This commit is contained in:
Jan Stárek
2019-11-24 02:51:11 +01:00
parent 628f296e97
commit bdbb2e5e4c

View File

@@ -34,7 +34,7 @@ namespace Parser
string basePath = string.Empty; string basePath = string.Empty;
if (openApiDocument.Servers.Any()) if (openApiDocument.Servers.Any())
{ {
basePath = new Uri(openApiDocument.Servers.First().Url).AbsolutePath; basePath = GetUriFromServer(openApiDocument.Servers.First())?.AbsolutePath;
} }
if (basePath == "/") if (basePath == "/")
@@ -42,5 +42,17 @@ namespace Parser
return basePath; return basePath;
} }
static Uri GetUriFromServer(OpenApiServer server)
{
try
{
return new Uri(server.Url);
}
catch (UriFormatException)
{
return null;
}
}
} }
} }