Skip to content

Commit

Permalink
feat: add error code (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberhck authored Aug 11, 2022
1 parent 4e422d6 commit cf58ff5
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion API/ExceptionHandler.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
using System.Text;
using Newtonsoft.Json.Serialization;

namespace API;

public class ExceptionHandler : IErrorFilter
Expand All @@ -6,6 +9,11 @@ public IError OnError(IError error)
{
return error.Exception == null
? error
: error.WithMessage(error.Exception.Message);
: error.WithMessage(error.Exception.Message).WithCode(ToSnakeCase(error.Exception.GetType().Name).ToUpper());
}

private static string ToSnakeCase(string text)
{
return new SnakeCaseNamingStrategy().GetPropertyName(text, false);
}
}

0 comments on commit cf58ff5

Please sign in to comment.