Files
parr_api/PARR.Core/Services/Task/Handlers/HandlerResult.cs

50 lines
1.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

namespace PARR.Core.Services.Task.Handlers
{
/// <summary>
/// Результат выполнения задачи обработчиком.
/// Используется для преедачи данных между BaseTaskHandler и конкретными хендлерами.
/// </summary>
public class HandlerResult
{
// TODO: может его перенести в Domain
/// <summary>
/// Успешно ли выполнено
/// </summary>
public bool IsSuccess { get; set; }
/// <summary>
/// Данные результата (JSON, если нужно сохранить в БД)
/// </summary>
public string? ResultData { get; set; }
/// <summary>
/// Сообщение об ошибке (если IsSuccess = false)
/// </summary>
public string? ErrorMessage { get; set; }
/// <summary>
/// Исключение
/// </summary>
public Exception? Exception { get; set; }
/// <summary>
/// Создать успешный результат
/// </summary>
/// <param name="resultData"></param>
/// <returns></returns>
public static HandlerResult Success(string? resultData = null) => new() { IsSuccess = true, ResultData = resultData };
/// <summary>
/// Создать результат с ошибкой
/// </summary>
/// <param name="errorMessage"></param>
/// <param name="ex"></param>
/// <returns></returns>
public static HandlerResult Failure(string errorMessage, Exception? ex = null) => new() { IsSuccess = false, ErrorMessage = errorMessage, Exception = ex };
}
}