diff --git a/src/SharedNetCoreLibrary/Models/DTO/ErrorDto.cs b/src/SharedNetCoreLibrary/Models/DTO/ErrorDto.cs new file mode 100644 index 0000000..13644c8 --- /dev/null +++ b/src/SharedNetCoreLibrary/Models/DTO/ErrorDto.cs @@ -0,0 +1,35 @@ +using CommunityToolkit.Mvvm.ComponentModel; + +namespace AndreasReitberger.Shared.Core.Models.DTO +{ + public partial class ErrorDto : ObservableObject + { + #region Properties + + [ObservableProperty] + public partial string Type { get; set; } = string.Empty; + + [ObservableProperty] + public partial string Message { get; set; } = string.Empty; + + [ObservableProperty] + public partial string? StackTrace { get; set; } + + [ObservableProperty] + public partial ErrorDto? InnerError { get; set; } + + #endregion + + #region Ctor + public ErrorDto() { } + public ErrorDto(string type, string message, string? stackTrace, ErrorDto? innerError) : this() + { + Type = type; + Message = message; + StackTrace = stackTrace; + InnerError = innerError; + } + + #endregion + } +} diff --git a/src/SharedNetCoreLibrary/Utilities/DtoMapper.cs b/src/SharedNetCoreLibrary/Utilities/DtoMapper.cs new file mode 100644 index 0000000..004ad72 --- /dev/null +++ b/src/SharedNetCoreLibrary/Utilities/DtoMapper.cs @@ -0,0 +1,16 @@ +using AndreasReitberger.Shared.Core.Models.DTO; + +namespace AndreasReitberger.Shared.Core.Utilities +{ + public static class DtoMapper + { + public static ErrorDto? FromException(Exception? ex) => + ex is null ? null : + new ErrorDto( + ex.GetType().FullName ?? "System.Exception", + ex.Message, + ex.StackTrace, + FromException(ex.InnerException)); + + } +}