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:
parent
96979079ba
commit
d69ad2e32e
@ -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;
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user