Browse Source

Catch the exception and log it to prevent crashing the application.

pull/20565/head
maliming 2 years ago
parent
commit
8467434c87
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 7
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs
  2. 24
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Libs/AbpMvcLibsService.cs

7
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs

@ -232,7 +232,7 @@ public class AbpAspNetCoreMvcModule : AbpModule
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
AddApplicationParts(context);
context.ServiceProvider.GetRequiredService<IAbpMvcLibsService>().CheckLibs(context);
CheckLibs(context);
}
private static void AddApplicationParts(ApplicationInitializationContext context)
@ -279,4 +279,9 @@ public class AbpAspNetCoreMvcModule : AbpModule
partManager.ApplicationParts.AddIfNotContains(moduleAssembly);
}
}
private static void CheckLibs(ApplicationInitializationContext context)
{
context.ServiceProvider.GetRequiredService<IAbpMvcLibsService>().CheckLibs(context);
}
}

24
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Libs/AbpMvcLibsService.cs

@ -1,3 +1,4 @@
using System;
using System.IO;
using System.Linq;
using System.Net;
@ -40,7 +41,7 @@ public class AbpMvcLibsService : IAbpMvcLibsService, ITransientDependency
" <h1>⚠️ The Libs folder under the <code style='background-color: #e7e7e7;'>wwwroot/libs</code> directory is empty!</h1>" +
" <p>The Libs folder contains mandatory NPM Packages for running the project.</p>" +
" <p>Make sure you run the <code style='background-color: #e7e7e7;'>abp install-libs</code> CLI tool command.</p>" +
" <p>For more information, check out the <a href='https://abp.io/docs/latest/CLI#install-libs'>ABP CLI documentation</a></p>" +
" <p>For more information, check out the <a href='https://abp.io/docs/latest/CLI#install-libs'>ABP CLI documentation</a></p>" +
" </body>" +
"</html>",
Encoding.UTF8
@ -65,14 +66,23 @@ public class AbpMvcLibsService : IAbpMvcLibsService, ITransientDependency
protected virtual Task<bool> CheckLibsAsync(HttpContext httpContext)
{
var fileProvider = new PhysicalFileProvider(httpContext.RequestServices.GetRequiredService<IWebHostEnvironment>().WebRootPath);
var libsFolder = fileProvider.GetDirectoryContents("/libs");
if (!libsFolder.Exists || !libsFolder.Any())
var logger = httpContext.RequestServices.GetRequiredService<ILogger<AbpMvcLibsService>>();
try
{
var logger = httpContext.RequestServices.GetRequiredService<ILogger<AbpMvcLibsService>>();
logger.LogError("The 'wwwroot/libs' folder does not exist or empty!");
return Task.FromResult(false);
var fileProvider = new PhysicalFileProvider(httpContext.RequestServices.GetRequiredService<IWebHostEnvironment>().WebRootPath);
var libsFolder = fileProvider.GetDirectoryContents("/libs");
if (!libsFolder.Exists || !libsFolder.Any())
{
logger.LogError("The 'wwwroot/libs' folder does not exist or empty!");
return Task.FromResult(false);
}
}
catch (Exception e)
{
// In case of any exception, log it and return true to prevent crashing the application.
logger.LogError(e, "An error occurred while checking the libs folder!");
}
return Task.FromResult(true);
}
}

Loading…
Cancel
Save