24 lines
615 B
C#
24 lines
615 B
C#
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace StopShopping.Api.Middlewares;
|
|
|
|
public static class ProblemDetailsExtensions
|
|
{
|
|
private const string CODE_FIELD = "code";
|
|
public static ProblemDetails AddErrorCode(this ProblemDetails problemDetails, ProblemDetailsCodes code)
|
|
{
|
|
problemDetails.Extensions ??= new Dictionary<string, object?>();
|
|
|
|
problemDetails.Extensions.Add(CODE_FIELD, (int)code);
|
|
return problemDetails;
|
|
}
|
|
}
|
|
|
|
public enum ProblemDetailsCodes
|
|
{
|
|
CsrfValidationFailed = 1000,
|
|
ParametersValidationFailed = 1001,
|
|
BadParameters = 1002,
|
|
ServerError = 1003,
|
|
}
|