1
0
mirror of https://github.com/bitwarden/server.git synced 2025-03-02 04:11:04 +01:00

handle stripe card errors

This commit is contained in:
Kyle Spearrin 2017-04-11 12:27:13 -04:00
parent 96979079ba
commit d69ad2e32e
2 changed files with 26 additions and 0 deletions

View File

@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.IdentityModel.Tokens;
using Stripe;
namespace Bit.Api.Utilities
{
@ -24,6 +25,7 @@ namespace Bit.Api.Utilities
}
var badRequestException = exception as BadRequestException;
var stripeException = exception as StripeException;
if(badRequestException != null)
{
context.HttpContext.Response.StatusCode = 400;
@ -37,6 +39,11 @@ namespace Bit.Api.Utilities
errorModel.Message = badRequestException.Message;
}
}
else if(stripeException != null && stripeException?.StripeError?.ErrorType == "card_error")
{
context.HttpContext.Response.StatusCode = 400;
errorModel = new ErrorResponseModel(stripeException.StripeError.Parameter, stripeException.Message);
}
else if(exception is ApplicationException)
{
context.HttpContext.Response.StatusCode = 402;

View File

@ -47,6 +47,25 @@ namespace Bit.Core.Models.Api
}
}
public ErrorResponseModel(Dictionary<string, IEnumerable<string>> errors)
: this("Errors have occurred.", errors)
{ }
public ErrorResponseModel(string errorKey, string errorValue)
: this(errorKey, new string[] { errorValue })
{ }
public ErrorResponseModel(string errorKey, IEnumerable<string> errorValues)
: this(new Dictionary<string, IEnumerable<string>> { { errorKey, errorValues } })
{ }
public ErrorResponseModel(string message, Dictionary<string, IEnumerable<string>> errors)
: this()
{
Message = message;
ValidationErrors = errors;
}
public string Message { get; set; }
public Dictionary<string, IEnumerable<string>> ValidationErrors { get; set; }
// For use in development environments.