Skip to content

Commit

Permalink
Move token_argument_error_msg/2 to Exceptions module
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabian Zitter committed Sep 20, 2024
1 parent dd993e2 commit 01f1137
Show file tree
Hide file tree
Showing 18 changed files with 51 additions and 49 deletions.
6 changes: 3 additions & 3 deletions lib/ibanity/api/ponto_connect/account.ex
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ defmodule Ibanity.PontoConnect.Account do

def list(other) do
raise ArgumentError,
message: PontoConnect.RequestUtils.token_argument_error_msg("Accounts", other)
message: PontoConnect.Exceptions.token_argument_error_msg("Accounts", other)
end

@doc """
Expand Down Expand Up @@ -132,7 +132,7 @@ defmodule Ibanity.PontoConnect.Account do

def find(other, _id) do
raise ArgumentError,
message: PontoConnect.RequestUtils.token_argument_error_msg("Account", other)
message: PontoConnect.Exceptions.token_argument_error_msg("Account", other)
end

@doc """
Expand Down Expand Up @@ -185,7 +185,7 @@ defmodule Ibanity.PontoConnect.Account do

def delete(other, _id) do
raise ArgumentError,
message: PontoConnect.RequestUtils.token_argument_error_msg("Account", other)
message: PontoConnect.Exceptions.token_argument_error_msg("Account", other)
end

@doc false
Expand Down
6 changes: 3 additions & 3 deletions lib/ibanity/api/ponto_connect/bulk_payment.ex
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ defmodule Ibanity.PontoConnect.BulkPayment do

def create(other, _account_id, _attrs) do
raise ArgumentError,
message: PontoConnect.RequestUtils.token_argument_error_msg("BulkPayment", other)
message: PontoConnect.Exceptions.token_argument_error_msg("BulkPayment", other)
end

@doc """
Expand Down Expand Up @@ -168,7 +168,7 @@ defmodule Ibanity.PontoConnect.BulkPayment do

def find(other, _ids) do
raise ArgumentError,
message: PontoConnect.RequestUtils.token_argument_error_msg("BulkPayment", other)
message: PontoConnect.Exceptions.token_argument_error_msg("BulkPayment", other)
end

@doc """
Expand Down Expand Up @@ -234,7 +234,7 @@ defmodule Ibanity.PontoConnect.BulkPayment do

def delete(other, _ids) do
raise ArgumentError,
message: PontoConnect.RequestUtils.token_argument_error_msg("BulkPayment", other)
message: PontoConnect.Exceptions.token_argument_error_msg("BulkPayment", other)
end

@doc false
Expand Down
15 changes: 15 additions & 0 deletions lib/ibanity/api/ponto_connect/exceptions.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
defmodule Ibanity.PontoConnect.Exceptions do
@moduledoc false

@doc false
def token_argument_error_msg(resource_name, other) do
"""
Cannot access #{resource_name} with given arguments.
Expected one of:
- `%Ibanity.Request{}` with `:token` set
- `%Ibanity.PontoConnect.Token{}`
Got: #{inspect(other)}
"""
end
end
6 changes: 3 additions & 3 deletions lib/ibanity/api/ponto_connect/financial_institution.ex
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ defmodule Ibanity.PontoConnect.FinancialInstitution do

def list_organization(other) do
raise ArgumentError,
message: PontoConnect.RequestUtils.token_argument_error_msg("Financial Institutions", other)
message: PontoConnect.Exceptions.token_argument_error_msg("Financial Institutions", other)
end

@doc """
Expand Down Expand Up @@ -205,7 +205,7 @@ defmodule Ibanity.PontoConnect.FinancialInstitution do

def find_public(other, _id) do
raise ArgumentError,
message: PontoConnect.RequestUtils.token_argument_error_msg("FinancialInstitution", other)
message: PontoConnect.Exceptions.token_argument_error_msg("FinancialInstitution", other)
end

@doc """
Expand Down Expand Up @@ -261,7 +261,7 @@ defmodule Ibanity.PontoConnect.FinancialInstitution do

def find_organization(other, _id) do
raise ArgumentError,
message: PontoConnect.RequestUtils.token_argument_error_msg("FinancialInstitution", other)
message: PontoConnect.Exceptions.token_argument_error_msg("FinancialInstitution", other)
end

@doc false
Expand Down
2 changes: 1 addition & 1 deletion lib/ibanity/api/ponto_connect/integration.ex
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ defmodule Ibanity.PontoConnect.Integration do

def delete(other, _id) do
raise ArgumentError,
message: PontoConnect.RequestUtils.token_argument_error_msg("Integration", other)
message: PontoConnect.Exceptions.token_argument_error_msg("Integration", other)
end

@doc false
Expand Down
2 changes: 1 addition & 1 deletion lib/ibanity/api/ponto_connect/integration_account.ex
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ defmodule Ibanity.PontoConnect.IntegrationAccount do

def list(other) do
raise ArgumentError,
message: PontoConnect.RequestUtils.token_argument_error_msg("Integration Accounts", other)
message: PontoConnect.Exceptions.token_argument_error_msg("Integration Accounts", other)
end

@doc false
Expand Down
2 changes: 1 addition & 1 deletion lib/ibanity/api/ponto_connect/onboarding_details.ex
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ defmodule Ibanity.PontoConnect.OnboardingDetails do

def create(other, _attrs) do
raise ArgumentError,
message: PontoConnect.RequestUtils.token_argument_error_msg("OnboardingDetails", other)
message: PontoConnect.Exceptions.token_argument_error_msg("OnboardingDetails", other)
end

@doc """
Expand Down
6 changes: 3 additions & 3 deletions lib/ibanity/api/ponto_connect/payment.ex
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ defmodule Ibanity.PontoConnect.Payment do

def create(other, _account_or_id, _attrs) do
raise ArgumentError,
message: PontoConnect.RequestUtils.token_argument_error_msg("Payment", other)
message: PontoConnect.Exceptions.token_argument_error_msg("Payment", other)
end

@doc """
Expand Down Expand Up @@ -165,7 +165,7 @@ defmodule Ibanity.PontoConnect.Payment do

def find(other, _ids) do
raise ArgumentError,
message: PontoConnect.RequestUtils.token_argument_error_msg("Payment", other)
message: PontoConnect.Exceptions.token_argument_error_msg("Payment", other)
end

@doc """
Expand Down Expand Up @@ -232,7 +232,7 @@ defmodule Ibanity.PontoConnect.Payment do

def delete(other, _ids) do
raise ArgumentError,
message: PontoConnect.RequestUtils.token_argument_error_msg("Payment", other)
message: PontoConnect.Exceptions.token_argument_error_msg("Payment", other)
end

@doc false
Expand Down
3 changes: 1 addition & 2 deletions lib/ibanity/api/ponto_connect/payment_activation_request.ex
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ defmodule Ibanity.PontoConnect.PaymentActivationRequest do

def create(other, _attrs) do
raise ArgumentError,
message:
PontoConnect.RequestUtils.token_argument_error_msg("PaymentActivationRequest", other)
message: PontoConnect.Exceptions.token_argument_error_msg("PaymentActivationRequest", other)
end

@doc """
Expand Down
6 changes: 3 additions & 3 deletions lib/ibanity/api/ponto_connect/payment_request.ex
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ defmodule Ibanity.PontoConnect.PaymentRequest do

def create(other, _account_or_id, _attrs) do
raise ArgumentError,
message: PontoConnect.RequestUtils.token_argument_error_msg("PaymentRequest", other)
message: PontoConnect.Exceptions.token_argument_error_msg("PaymentRequest", other)
end

@doc """
Expand Down Expand Up @@ -160,7 +160,7 @@ defmodule Ibanity.PontoConnect.PaymentRequest do

def find(other, _id) do
raise ArgumentError,
message: PontoConnect.RequestUtils.token_argument_error_msg("PaymentRequest", other)
message: PontoConnect.Exceptions.token_argument_error_msg("PaymentRequest", other)
end

@doc """
Expand Down Expand Up @@ -223,7 +223,7 @@ defmodule Ibanity.PontoConnect.PaymentRequest do

def delete(other, _ids) do
raise ArgumentError,
message: PontoConnect.RequestUtils.token_argument_error_msg("PaymentRequest", other)
message: PontoConnect.Exceptions.token_argument_error_msg("PaymentRequest", other)
end

@doc false
Expand Down
2 changes: 1 addition & 1 deletion lib/ibanity/api/ponto_connect/reauthorization_request.ex
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ defmodule Ibanity.PontoConnect.ReauthorizationRequest do

def create(other, _account_or_id, _attrs) do
raise ArgumentError,
message: PontoConnect.RequestUtils.token_argument_error_msg("ReauthorizationRequest", other)
message: PontoConnect.Exceptions.token_argument_error_msg("ReauthorizationRequest", other)
end

@doc """
Expand Down
12 changes: 0 additions & 12 deletions lib/ibanity/api/ponto_connect/request_utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,6 @@ defmodule Ibanity.PontoConnect.RequestUtils do
end
end

@doc false
def token_argument_error_msg(resource_name, other) do
"""
Cannot access #{resource_name} with given arguments.
Expected one of:
- `%Ibanity.Request{}` with `:token` set
- `%Ibanity.PontoConnect.Token{}`
Got: #{inspect(other)}
"""
end

@doc false
def create_token_default_request(%Request{} = request) do
new_attributes =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ defmodule Ibanity.PontoConnect.Sandbox.FinancialInstitutionAccount do
def list(other, _financial_institution__or_id) do
raise ArgumentError,
message:
PontoConnect.RequestUtils.token_argument_error_msg("FinancialInstitutionAccount", other)
PontoConnect.Exceptions.token_argument_error_msg("FinancialInstitutionAccount", other)
end

@doc """
Expand Down Expand Up @@ -155,7 +155,7 @@ defmodule Ibanity.PontoConnect.Sandbox.FinancialInstitutionAccount do
def find(other, _id) do
raise ArgumentError,
message:
PontoConnect.RequestUtils.token_argument_error_msg("FinancialInstitutionAccount", other)
PontoConnect.Exceptions.token_argument_error_msg("FinancialInstitutionAccount", other)
end

@doc false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ defmodule Ibanity.PontoConnect.Sandbox.FinancialInstitutionTransaction do
def create(other, _ids, _attrs) do
raise ArgumentError,
message:
PontoConnect.RequestUtils.token_argument_error_msg(
PontoConnect.Exceptions.token_argument_error_msg(
"FinancialInstitutionTransaction",
other
)
Expand Down Expand Up @@ -209,7 +209,7 @@ defmodule Ibanity.PontoConnect.Sandbox.FinancialInstitutionTransaction do
def list(other, _ids) do
raise ArgumentError,
message:
PontoConnect.RequestUtils.token_argument_error_msg(
PontoConnect.Exceptions.token_argument_error_msg(
"FinancialInstitutionTransaction",
other
)
Expand Down Expand Up @@ -290,7 +290,7 @@ defmodule Ibanity.PontoConnect.Sandbox.FinancialInstitutionTransaction do
def find(other, _id) do
raise ArgumentError,
message:
PontoConnect.RequestUtils.token_argument_error_msg(
PontoConnect.Exceptions.token_argument_error_msg(
"FinancialInstitutionTransaction",
other
)
Expand Down Expand Up @@ -367,7 +367,7 @@ defmodule Ibanity.PontoConnect.Sandbox.FinancialInstitutionTransaction do
def update(other, _ids, _attrs) do
raise ArgumentError,
message:
PontoConnect.RequestUtils.token_argument_error_msg(
PontoConnect.Exceptions.token_argument_error_msg(
"FinancialInstitutionTransaction",
other
)
Expand Down
4 changes: 2 additions & 2 deletions lib/ibanity/api/ponto_connect/synchronization.ex
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ defmodule Ibanity.PontoConnect.Synchronization do

def create(other, _attrs) do
raise ArgumentError,
message: PontoConnect.RequestUtils.token_argument_error_msg("Synchronization", other)
message: PontoConnect.Exceptions.token_argument_error_msg("Synchronization", other)
end

@doc """
Expand Down Expand Up @@ -144,7 +144,7 @@ defmodule Ibanity.PontoConnect.Synchronization do

def find(other, _id) do
raise ArgumentError,
message: PontoConnect.RequestUtils.token_argument_error_msg("Synchronization", other)
message: PontoConnect.Exceptions.token_argument_error_msg("Synchronization", other)
end

@doc false
Expand Down
12 changes: 6 additions & 6 deletions lib/ibanity/api/ponto_connect/transaction.ex
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ defmodule Ibanity.PontoConnect.Transaction do

def list(other, _account_id) do
raise ArgumentError,
message: PontoConnect.RequestUtils.token_argument_error_msg("Transactions", other)
message: PontoConnect.Exceptions.token_argument_error_msg("Transactions", other)
end

@doc """
Expand Down Expand Up @@ -164,7 +164,7 @@ defmodule Ibanity.PontoConnect.Transaction do

def list_updated_for_synchronization(other, _synchronization_id) do
raise ArgumentError,
message: PontoConnect.RequestUtils.token_argument_error_msg("Transactions", other)
message: PontoConnect.Exceptions.token_argument_error_msg("Transactions", other)
end

@doc """
Expand Down Expand Up @@ -236,7 +236,7 @@ defmodule Ibanity.PontoConnect.Transaction do

def list_updated_pending_for_synchronization(other, _synchronization_or_id) do
raise ArgumentError,
message: PontoConnect.RequestUtils.token_argument_error_msg("Transactions", other)
message: PontoConnect.Exceptions.token_argument_error_msg("Transactions", other)
end

@doc """
Expand Down Expand Up @@ -301,7 +301,7 @@ defmodule Ibanity.PontoConnect.Transaction do

def list_pending_for_account(other, _account_or_id) do
raise ArgumentError,
message: PontoConnect.RequestUtils.token_argument_error_msg("Transactions", other)
message: PontoConnect.Exceptions.token_argument_error_msg("Transactions", other)
end

@doc """
Expand Down Expand Up @@ -356,7 +356,7 @@ defmodule Ibanity.PontoConnect.Transaction do

def find(other, _ids) do
raise ArgumentError,
message: PontoConnect.RequestUtils.token_argument_error_msg("Transaction", other)
message: PontoConnect.Exceptions.token_argument_error_msg("Transaction", other)
end

@doc """
Expand Down Expand Up @@ -416,7 +416,7 @@ defmodule Ibanity.PontoConnect.Transaction do

def find_pending_for_account(other, _ids) do
raise ArgumentError,
message: PontoConnect.RequestUtils.token_argument_error_msg("Transaction", other)
message: PontoConnect.Exceptions.token_argument_error_msg("Transaction", other)
end

@doc false
Expand Down
2 changes: 1 addition & 1 deletion lib/ibanity/api/ponto_connect/usage.ex
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ defmodule Ibanity.PontoConnect.Usage do
def find(other, _ids) do
raise ArgumentError,
message:
PontoConnect.RequestUtils.token_argument_error_msg(
PontoConnect.Exceptions.token_argument_error_msg(
"FinancialInstitutionTransaction",
other
)
Expand Down
2 changes: 1 addition & 1 deletion lib/ibanity/api/ponto_connect/user_info.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ defmodule Ibanity.PontoConnect.UserInfo do

def myself(other) do
raise ArgumentError,
message: PontoConnect.RequestUtils.token_argument_error_msg("UserInfo", other)
message: PontoConnect.Exceptions.token_argument_error_msg("UserInfo", other)
end

@doc false
Expand Down

0 comments on commit 01f1137

Please sign in to comment.