fix errors
Some checks failed
Build and Publish / build-release (push) Has been cancelled

This commit is contained in:
2026-05-15 14:12:18 -05:00
parent fbd3bc9772
commit 39527d49a1
4 changed files with 8 additions and 68 deletions

View File

@@ -31,7 +31,7 @@ defmodule CustomerService.Aggregates.CustomerId do
end
defimpl String.Chars do
def to_string(%CustomerService.Aggregates.LeadId{
def to_string(%CustomerService.Aggregates.CustomerId{
org_id: org_id,
customer_type: type,
customer_id: customer_id

View File

@@ -13,7 +13,7 @@ defmodule CustomerService.Projectors.Customer do
%CustomerService.Aggregates.CustomerId{org_id: org_id, customer_id: customer_id} = event.id
Ecto.Multi.insert(multi, :customer, %Customer{
id: CustomerId.to_string(event.id),
id: to_string(event.id),
org_id: org_id,
customer_id: customer_id,
customer_type: "individual",
@@ -42,7 +42,7 @@ defmodule CustomerService.Projectors.Customer do
%CustomerService.Aggregates.CustomerId{org_id: org_id, customer_id: customer_id} = e.id
Ecto.Multi.insert(multi, :customer, %Customer{
id: CustomerId.to_string(e.id),
id: to_string(e.id),
org_id: org_id,
customer_id: customer_id,
customer_type: "corporate",
@@ -58,7 +58,7 @@ defmodule CustomerService.Projectors.Customer do
end)
project(%Events.CustomerUpdated{} = e, _meta, fn multi ->
composite_id = CustomerId.to_string(e.id)
composite_id = to_string(e.id)
Ecto.Multi.update_all(multi, :customer, from(c in Customer, where: c.id == ^composite_id),
set: [
@@ -75,7 +75,7 @@ defmodule CustomerService.Projectors.Customer do
end)
project(%Events.CorporateCustomerUpdated{} = e, _meta, fn multi ->
composite_id = CustomerId.to_string(e.id)
composite_id = to_string(e.id)
Ecto.Multi.update_all(multi, :customer, from(c in Customer, where: c.id == ^composite_id),
set: [

View File

@@ -13,7 +13,7 @@ defmodule CustomerService.Projectors.QuickLead do
%CustomerService.Aggregates.LeadId{org_id: org_id, lead_id: lead_id} = event.id
Ecto.Multi.insert(multi, :quick_lead, %QuickLead{
id: LeadId.to_string(event.id),
id: to_string(event.id),
org_id: org_id,
lead_id: lead_id,
name: event.name,
@@ -38,7 +38,7 @@ defmodule CustomerService.Projectors.QuickLead do
end)
project(%Events.QuickLeadUpdated{} = event, _meta, fn multi ->
composite_id = LeadId.to_string(event.id)
composite_id = to_string(event.id)
Ecto.Multi.update_all(multi, :quick_lead, from(q in QuickLead, where: q.id == ^composite_id),
set: [
@@ -55,7 +55,7 @@ defmodule CustomerService.Projectors.QuickLead do
end)
project(%Events.LeadStatusUpdated{} = event, _meta, fn multi ->
composite_id = LeadId.to_string(event.id)
composite_id = to_string(event.id)
Ecto.Multi.update_all(multi, :quick_lead, from(q in QuickLead, where: q.id == ^composite_id),
set: [

View File

@@ -1,60 +0,0 @@
defmodule CustomerServiceWeb.ErrorJSON do
@moduledoc """
This module is invoked by your endpoint in case of errors on JSON requests.
"""
alias Ecto.Changeset
alias OpenApiSpex.Error
def render("404.json", _assigns) do
%{errors: %{detail: "Not Found"}}
end
def render("500.json", assigns) do
detail = detailed_message(assigns[:reason], "Internal Server Error")
%{errors: %{detail: detail}}
end
def render("400.json", assigns) do
detail = detailed_message(assigns[:reason], "Bad Request")
%{errors: %{detail: detail}}
end
def render("422.json", assigns) do
detail = detailed_message(assigns[:reason], "Unprocessable Entity")
%{errors: %{detail: detail}}
end
def render(template, assigns) do
detail =
detailed_message(
assigns[:reason],
Phoenix.Controller.status_message_from_template(template)
)
%{errors: %{detail: detail}}
end
defp detailed_message(nil, default), do: default
defp detailed_message(%Changeset{} = changeset, _default) do
format_changeset_errors(changeset)
|> inspect()
end
defp detailed_message(%Error{errors: errors}, _default) do
Enum.map_join(errors, ", ", fn e -> "#{e.code}: #{e.message}" end)
end
defp detailed_message(reason, _default) do
inspect(reason, pretty: true)
end
defp format_changeset_errors(changeset) do
Changeset.traverse_errors(changeset, fn {msg, opts} ->
Enum.reduce(opts, msg, fn {key, value}, acc ->
String.replace(acc, "%{#{key}}", to_string(value))
end)
end)
end
end