Skip to content

CommerceErrorModel

// RB2 Core Connect
namespace CoreConnect.Commerce.Exceptions;
public record CommerceErrorModel
{
public CommerceErrorModel(string code, string message, string referenceCode = "", object? data = default, int? statuscode = 0)
{
Code = code;
StatusCode = statuscode;
ReferenceCode = referenceCode;
Message = message;
Data = data;
}
/// <summary>
/// High level error code
/// <seealso cref="ErrorCodes"/>
/// </summary>
public string Code { get; }
/// <summary>
/// Core connect reference code
/// <seealso cref="ErrorReferenceCodes"/>
/// </summary>
public string ReferenceCode { get; }
public string Message { get; }
public object? Data { get; }
public int? StatusCode { get; set; }
public static CommerceErrorModel FromHttpStatus(int httpStatus, string message = "")
{
var code = httpStatus switch
{
400 => ErrorCodes.BAD_REQUEST,
401 => ErrorCodes.UNAUTHENTICATED,
403 => ErrorCodes.FORBIDDEN,
404 => ErrorCodes.NOT_FOUND,
422 => ErrorCodes.INVALID_DATA,
_ => ErrorCodes.INTERNAL_SERVER_ERROR
};
return new CommerceErrorModel(code, message, string.Empty, null, httpStatus);
}
}