Skip to content

Commit b734380

Browse files
onetarunhishamco
authored andcommitted
Throw exception if file null or empty
1 parent 16dd7cb commit b734380

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/Modules/SimplCommerce.Module.StorageLocal/LocalStorageService.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.IO;
1+
using System;
2+
using System.IO;
23
using System.Threading.Tasks;
34
using SimplCommerce.Infrastructure;
45
using SimplCommerce.Module.Core.Services;
@@ -32,10 +33,11 @@ public async Task SaveMediaAsync(Stream mediaBinaryStream, string fileName, stri
3233

3334
public async Task DeleteMediaAsync(string fileName)
3435
{
35-
if (!string.IsNullOrEmpty(fileName))
36+
if (string.IsNullOrWhiteSpace(fileName))
3637
{
37-
38-
var filePath = Path.Combine(GlobalConfiguration.WebRootPath, MediaRootFoler, fileName);
38+
throw new ArgumentException("Filename cannot be null, empty, or whitespace.", nameof(fileName));
39+
}
40+
var filePath = Path.Combine(GlobalConfiguration.WebRootPath, MediaRootFoler, fileName);
3941
if (File.Exists(filePath))
4042
{
4143
await Task.Run(() => File.Delete(filePath));

0 commit comments

Comments
 (0)