Skip to content

Commit

Permalink
Merge pull request #96 from wemogy/main
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
SebastianKuesters authored Jul 10, 2024
2 parents a20a92f + 0ecb5fd commit a0b6a3f
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 2 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ jobs:
tests:
name: Tests
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v2

Expand All @@ -33,7 +36,7 @@ jobs:
output: 'both'

- name: Add Coverage PR Comment
uses: marocchino/sticky-pull-request-comment@v2.5.0
uses: marocchino/sticky-pull-request-comment@v2
if: github.event_name == 'pull_request' && github.actor != 'dependabot[bot]'
with:
recreate: true
Expand Down
1 change: 0 additions & 1 deletion src/Wemogy.Core/Errors/Exceptions/ErrorException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ public abstract class ErrorException : Exception
{
public ErrorType ErrorType { get; set; }
public string Code { get; set; }

public string Description { get; set; }

protected ErrorException(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Wemogy.Core.Errors.Enums;

namespace Wemogy.Core.Json.ExceptionInformation
{
public class ErrorExceptionInformation
{
public ErrorType ErrorType { get; set; }
public string Code { get; set; }
public string Description { get; set; }

public ErrorExceptionInformation(
ErrorType errorType,
string code,
string description)
{
ErrorType = errorType;
Code = code;
Description = description;
}
}
}
18 changes: 18 additions & 0 deletions src/Wemogy.Core/Json/ExceptionInformation/ExceptionInformation.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Wemogy.Core.Errors.Exceptions;

namespace Wemogy.Core.Json.ExceptionInformation
{
Expand All @@ -14,6 +15,8 @@ public class ExceptionInformation
public string? StackTrace { get; set; }
public ExceptionInformation? InnerException { get; set; }

public ErrorExceptionInformation? ErrorExceptionInformation { get; set; }

public ExceptionInformation(
Exception exception,
bool includeInnerException = true,
Expand All @@ -32,6 +35,21 @@ public ExceptionInformation(
{
InnerException = new ExceptionInformation(exception.InnerException, includeInnerException, includeStackTrace);
}

if (exception is ErrorException errorException)
{
ErrorExceptionInformation = new ErrorExceptionInformation(
errorException.ErrorType,
errorException.Code,
errorException.Description);
}
}

public ExceptionInformation()
{
ExceptionType = string.Empty;
Message = string.Empty;
Source = string.Empty;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using Wemogy.Core.Errors;
using Wemogy.Core.Errors.Enums;
using Wemogy.Core.Extensions;

namespace Wemogy.Core.Json.ExceptionInformation
Expand All @@ -14,5 +16,34 @@ public static string ToJson(this Exception exception, bool includeInnerException
{
return exception.ToExceptionInformation(includeInnerException, includeStackTrace).ToJson();
}

public static Exception ToException(this ExceptionInformation exceptionInformation)
{
// destructure
var errorExceptionInformation = exceptionInformation.ErrorExceptionInformation;

if (errorExceptionInformation != null)
{
switch (errorExceptionInformation.ErrorType)
{
case ErrorType.Failure:
return Error.Failure(errorExceptionInformation.Code, errorExceptionInformation.Description);
case ErrorType.Unexpected:
return Error.Unexpected(errorExceptionInformation.Code, errorExceptionInformation.Description);
case ErrorType.Validation:
return Error.Validation(errorExceptionInformation.Code, errorExceptionInformation.Description);
case ErrorType.Conflict:
return Error.Conflict(errorExceptionInformation.Code, errorExceptionInformation.Description);
case ErrorType.NotFound:
return Error.NotFound(errorExceptionInformation.Code, errorExceptionInformation.Description);
case ErrorType.Authorization:
return Error.Authorization(errorExceptionInformation.Code, errorExceptionInformation.Description);
case ErrorType.PreconditionFailed:
return Error.PreconditionFailed(errorExceptionInformation.Code, errorExceptionInformation.Description);
}
}

return new Exception(exceptionInformation.Message);
}
}
}

0 comments on commit a0b6a3f

Please sign in to comment.