Skip to content

Commit 153dfcc

Browse files
committed
Add try...catch block to handle errors
1 parent 20e5a36 commit 153dfcc

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/Aliencube.AzureFunctions.Extensions.OpenApi.CLI/Program.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ public void Generate(
8080
var helper = new DocumentHelper(filter);
8181
var document = new Document(helper);
8282

83-
var swagger = document.InitialiseDocument()
83+
var swagger = default(string);
84+
try
85+
{
86+
swagger = document.InitialiseDocument()
8487
.AddMetadata(pi.OpenApiInfo)
8588
#if NET461
8689
.AddServer(req, pi.HostJsonHttpSettings.RoutePrefix)
@@ -90,6 +93,15 @@ public void Generate(
9093
.Build(assembly)
9194
.RenderAsync(version.ToOpenApiSpecVersion(), format.ToOpenApiFormat())
9295
.Result;
96+
}
97+
catch (Exception ex)
98+
{
99+
Console.WriteLine(ex.Message);
100+
Console.WriteLine(ex.StackTrace);
101+
#if NET461
102+
req.Dispose();
103+
#endif
104+
}
93105
#if NET461
94106
req.Dispose();
95107
#endif

src/Aliencube.AzureFunctions.Extensions.OpenApi.CLI/ProjectInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ private void SetOpenApiInfo()
253253
this.OpenApiSettingsJsonPath.ThrowIfNullOrWhiteSpace();
254254
this.LocalSettingsJsonPath.ThrowIfNullOrWhiteSpace();
255255

256-
var openApiInfo = this.HostSettings.Get<OpenApiInfo>("openApi");
256+
var openApiInfo = this.HostSettings.Get<OpenApiInfo>("openApi:info");
257257
if (this.IsValidOpenApiInfo(openApiInfo))
258258
{
259259
this.OpenApiInfo = openApiInfo;
@@ -264,7 +264,7 @@ private void SetOpenApiInfo()
264264
if (File.Exists(this.OpenApiSettingsJsonPath))
265265
{
266266
var openapiSettings = File.ReadAllText(this.OpenApiSettingsJsonPath, Encoding.UTF8);
267-
openApiInfo = JsonConvert.DeserializeObject<OpenApiInfo>(openapiSettings);
267+
openApiInfo = JsonConvert.DeserializeObject<OpenApiSettings>(openapiSettings).Info;
268268
if (this.IsValidOpenApiInfo(openApiInfo))
269269
{
270270
this.OpenApiInfo = openApiInfo;

0 commit comments

Comments
 (0)