Skip to content

Commit

Permalink
Prevent swallowing of stripe errors
Browse files Browse the repository at this point in the history
  • Loading branch information
begedin committed Dec 7, 2016
1 parent 1d82926 commit b325d59
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 51 deletions.
4 changes: 2 additions & 2 deletions lib/code_corps/stripe_service/stripe_connect_subscription.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ defmodule CodeCorps.StripeService.StripeConnectSubscriptionService do
# {:error, :project_not_ready} - `CodeCorps.ProjectSubscribable.validate/1` failed
# {:error, :user_not_ready} - `CodeCorps.UserCanSubscribe.validate/1` failed
# {:error, %Ecto.Changeset{}} - Record creation failed due to validation errors
# {:error, %Stripe.APIError{}} - Stripe request failed
# {:error, %Stripe.APIErrorResponse{}} - Stripe request failed
# {:error, :not_found} - One of the associated records was not found
{:error, error} -> {:error, error}
nil -> {:error, :not_found}
Expand All @@ -51,7 +51,7 @@ defmodule CodeCorps.StripeService.StripeConnectSubscriptionService do
else
# possible errors
# {:error, %Ecto.Changeset{}} - Record creation failed due to validation errors
# {:error, %Stripe.APIError{}} - Stripe request failed
# {:error, %Stripe.APIErrorResponse{}} - Stripe request failed
# {:error, :not_found} - One of the associated records was not found
{:error, error} -> {:error, error}
nil -> {:error, :not_found}
Expand Down
2 changes: 1 addition & 1 deletion lib/code_corps/stripe_service/stripe_platform_customer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ defmodule CodeCorps.StripeService.StripePlatformCustomerService do
- `{:ok, %CodeCorps.StriePlatformCustomer{}, %Stripe.Customer{}}` if everything was updated
- `{:error, %Ecto.Changeset{}}` -if there was a validation issue while updating the local record
- `{:error, %Stripe.APIErrorResposne{}}` - if there was a problem with updating the API record
- `{:error, %Stripe.APIErrorResponse{}}` - if there was a problem with updating the API record
- `{:error, :unhandled}` -if something unexpected went wrong
"""
def update(%StripePlatformCustomer{id_from_stripe: id_from_stripe} = customer, attributes) do
Expand Down
12 changes: 1 addition & 11 deletions web/controllers/stripe_connect_account_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,8 @@ defmodule CodeCorps.StripeConnectAccountController do
|> handle_create_result(conn)
end

defp handle_create_result({:error, %Ecto.Changeset{} = changeset}, _conn), do: changeset
defp handle_create_result({:ok, %StripeConnectAccount{}} = result, conn) do
result |> CodeCorps.Analytics.Segment.track(:created, conn)
end
defp handle_create_result({:error, %Stripe.APIErrorResponse{}}, conn) do
conn
|> put_status(500)
|> render(CodeCorps.ErrorView, "500.json-api")
end
defp handle_create_result({:error, %Stripe.OAuthAPIErrorResponse{}}, conn) do
conn
|> put_status(400)
|> render(CodeCorps.ErrorView, "stripe-400.json-api")
end
defp handle_create_result({:error, %Ecto.Changeset{} = changeset}, _conn), do: changeset
end
21 changes: 3 additions & 18 deletions web/controllers/stripe_connect_plan_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,13 @@ defmodule CodeCorps.StripeConnectPlanController do
|> handle_create_result(conn)
end

defp handle_create_result({:ok, %StripeConnectPlan{}} = result, conn) do
result |> CodeCorps.Analytics.Segment.track(:created, conn)
end
defp handle_create_result({:error, %Ecto.Changeset{} = changeset}, _conn), do: changeset
defp handle_create_result({:error, :project_not_ready}, conn) do
conn
|> put_status(422)
|> render(CodeCorps.ErrorView, "422.json-api")
end
defp handle_create_result({:error, %Stripe.APIErrorResponse{}}, conn) do
conn
|> put_status(500)
|> render(CodeCorps.ErrorView, "500.json-api")
end
defp handle_create_result({:error, %Stripe.OAuthAPIErrorResponse{}}, conn) do
conn
|> put_status(400)
|> render(CodeCorps.ErrorView, "stripe-400.json-api")
end
defp handle_create_result({:error, %Ecto.Changeset{} = changeset}, _conn), do: changeset
defp handle_create_result({:error, _error}, conn) do
conn
|> put_status(500)
|> render(CodeCorps.ErrorView, "500.json-api")
defp handle_create_result({:ok, %StripeConnectPlan{}} = result, conn) do
result |> CodeCorps.Analytics.Segment.track(:created, conn)
end
end
7 changes: 1 addition & 6 deletions web/controllers/stripe_connect_subscription_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,8 @@ defmodule CodeCorps.StripeConnectSubscriptionController do
|> handle_create_result(conn)
end

defp handle_create_result({:error, %Ecto.Changeset{} = changeset}, _conn), do: changeset
defp handle_create_result({:ok, %StripeConnectSubscription{}} = result, conn) do
result |> CodeCorps.Analytics.Segment.track(:created, conn)
end
defp handle_create_result({:error, %Stripe.APIErrorResponse{}}, conn) do
conn
|> put_status(500)
|> render(CodeCorps.ErrorView, "500.json-api")
end
defp handle_create_result({:error, %Ecto.Changeset{} = changeset}, _conn), do: changeset
end
7 changes: 1 addition & 6 deletions web/controllers/stripe_platform_card_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,8 @@ defmodule CodeCorps.StripePlatformCardController do
|> handle_create_result(conn)
end

defp handle_create_result({:error, %Ecto.Changeset{} = changeset}, _conn), do: changeset
defp handle_create_result({:ok, %StripePlatformCard{}} = result, conn) do
result |> CodeCorps.Analytics.Segment.track(:created, conn)
end
defp handle_create_result({:error, %Stripe.APIErrorResponse{}}, conn) do
conn
|> put_status(500)
|> render(CodeCorps.ErrorView, "500.json-api")
end
defp handle_create_result({:error, %Ecto.Changeset{} = changeset}, _conn), do: changeset
end
8 changes: 1 addition & 7 deletions web/controllers/stripe_platform_customer_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,8 @@ defmodule CodeCorps.StripePlatformCustomerController do
|> handle_create_result(conn)
end

defp handle_create_result({:error, %Ecto.Changeset{} = changeset}, _conn), do: changeset
defp handle_create_result({:ok, %StripePlatformCustomer{}} = result, conn) do
result |> CodeCorps.Analytics.Segment.track(:created, conn)
end

defp handle_create_result({:error, %Stripe.APIErrorResponse{}}, conn) do
conn
|> put_status(500)
|> render(CodeCorps.ErrorView, "500.json-api")
end
defp handle_create_result({:error, %Ecto.Changeset{} = changeset}, _conn), do: changeset
end

0 comments on commit b325d59

Please sign in to comment.