Skip to content

Commit

Permalink
Add try...catch block to handle errors
Browse files Browse the repository at this point in the history
  • Loading branch information
justinyoo committed Jul 12, 2020
1 parent 20e5a36 commit 153dfcc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 13 additions & 1 deletion src/Aliencube.AzureFunctions.Extensions.OpenApi.CLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ public void Generate(
var helper = new DocumentHelper(filter);
var document = new Document(helper);

var swagger = document.InitialiseDocument()
var swagger = default(string);
try
{
swagger = document.InitialiseDocument()
.AddMetadata(pi.OpenApiInfo)
#if NET461
.AddServer(req, pi.HostJsonHttpSettings.RoutePrefix)
Expand All @@ -90,6 +93,15 @@ public void Generate(
.Build(assembly)
.RenderAsync(version.ToOpenApiSpecVersion(), format.ToOpenApiFormat())
.Result;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
#if NET461
req.Dispose();
#endif
}
#if NET461
req.Dispose();
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ private void SetOpenApiInfo()
this.OpenApiSettingsJsonPath.ThrowIfNullOrWhiteSpace();
this.LocalSettingsJsonPath.ThrowIfNullOrWhiteSpace();

var openApiInfo = this.HostSettings.Get<OpenApiInfo>("openApi");
var openApiInfo = this.HostSettings.Get<OpenApiInfo>("openApi:info");
if (this.IsValidOpenApiInfo(openApiInfo))
{
this.OpenApiInfo = openApiInfo;
Expand All @@ -264,7 +264,7 @@ private void SetOpenApiInfo()
if (File.Exists(this.OpenApiSettingsJsonPath))
{
var openapiSettings = File.ReadAllText(this.OpenApiSettingsJsonPath, Encoding.UTF8);
openApiInfo = JsonConvert.DeserializeObject<OpenApiInfo>(openapiSettings);
openApiInfo = JsonConvert.DeserializeObject<OpenApiSettings>(openapiSettings).Info;
if (this.IsValidOpenApiInfo(openApiInfo))
{
this.OpenApiInfo = openApiInfo;
Expand Down

0 comments on commit 153dfcc

Please sign in to comment.