mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-20 10:40:29 +01:00
28 lines
1.0 KiB
C#
28 lines
1.0 KiB
C#
using System.Collections.Generic;
|
|
using BTCPayServer.Client.Models;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
|
|
|
namespace BTCPayServer.Controllers.GreenField
|
|
{
|
|
public static class GreenFieldUtils
|
|
{
|
|
public static IActionResult CreateValidationError(this ControllerBase controller, ModelStateDictionary modelState)
|
|
{
|
|
List<GreenfieldValidationError> errors = new List<GreenfieldValidationError>();
|
|
foreach (var error in modelState)
|
|
{
|
|
foreach (var errorMessage in error.Value.Errors)
|
|
{
|
|
errors.Add(new GreenfieldValidationError(error.Key, errorMessage.ErrorMessage));
|
|
}
|
|
}
|
|
return controller.UnprocessableEntity(errors.ToArray());
|
|
}
|
|
public static IActionResult CreateAPIError(this ControllerBase controller, string errorCode, string errorMessage)
|
|
{
|
|
return controller.BadRequest(new GreenfieldAPIError(errorCode, errorMessage));
|
|
}
|
|
}
|
|
}
|