Skip to content

Commit

Permalink
Merge pull request #22 from PandaTechAM/development
Browse files Browse the repository at this point in the history
Add BaseConverter library exception handling
  • Loading branch information
ruboarm committed May 7, 2024
2 parents 00c5399 + 1b9e270 commit f9943ce
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
22 changes: 22 additions & 0 deletions src/ResponseCrafter/PandaExceptionHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Reflection;
using BaseConverter.Exceptions;
using EFCoreQueryMagic.Exceptions;
using FluentImporter.Exceptions;
using Microsoft.AspNetCore.Http;
Expand Down Expand Up @@ -50,13 +51,34 @@ public async ValueTask<bool> TryHandleAsync(HttpContext httpContext, Exception e
case ImportException targetInvocationException:
await HandleImportExceptionAsync(httpContext, targetInvocationException, cancellationToken);
break;
case BaseConverterException targetInvocationException:
await HandleBaseConverterExceptionAsync(httpContext, targetInvocationException, cancellationToken);
break;
default:
await HandleGeneralExceptionAsync(httpContext, exception, cancellationToken);
break;
}

return true;
}

private async Task HandleBaseConverterExceptionAsync(HttpContext httpContext, BaseConverterException importException,
CancellationToken cancellationToken)
{
switch (importException)
{
case InputValidationException _:
case UnsupportedCharacterException _:
var exceptionName = importException.GetType().Name;
var formattedMessage = $"{exceptionName} in Import: {importException.Message} {importException.Value}";
var mappedException = new BadRequestException(formattedMessage);
await HandleApiExceptionAsync(httpContext, mappedException, cancellationToken);
break;
default:
await HandleGeneralExceptionAsync(httpContext, importException, cancellationToken);
break;
}
}

private async Task HandleImportExceptionAsync(HttpContext httpContext, ImportException importException,
CancellationToken cancellationToken)
Expand Down
4 changes: 2 additions & 2 deletions src/ResponseCrafter/ResponseCrafter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Copyright>MIT</Copyright>
<PackageIcon>pandatech.png</PackageIcon>
<PackageReadmeFile>Readme.md</PackageReadmeFile>
<Version>1.4.8</Version>
<Version>1.4.9</Version>
<PackageId>Pandatech.ResponseCrafter</PackageId>
<PackageTags>Pandatech, library, exception handler, exception, middleware, Api response</PackageTags>
<Title>ResponseCrafter</Title>
Expand All @@ -24,7 +24,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.3" />
<PackageReference Include="Pandatech.EFCoreQueryMagic" Version="1.0.7" />
<PackageReference Include="Pandatech.EFCoreQueryMagic" Version="1.0.8" />
<PackageReference Include="PandaTech.FluentImporter" Version="2.0.6" />
<PackageReference Include="PandaTech.ServiceResponse" Version="1.2.12" />
</ItemGroup>
Expand Down

0 comments on commit f9943ce

Please sign in to comment.