2021-03-16 08:51:17 +13:00
|
|
|
defprotocol AshGraphql.Error do
|
|
|
|
def to_error(exception)
|
|
|
|
end
|
|
|
|
|
|
|
|
defimpl AshGraphql.Error, for: Ash.Error.Query.InvalidQuery do
|
|
|
|
def to_error(error) do
|
|
|
|
%{
|
|
|
|
message: Exception.message(error),
|
|
|
|
code: Ash.ErrorKind.code(error),
|
|
|
|
fields: [error.field]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
defimpl AshGraphql.Error, for: Ash.Error.Changes.InvalidAttribute do
|
|
|
|
def to_error(error) do
|
|
|
|
%{
|
|
|
|
message: Exception.message(error),
|
|
|
|
code: Ash.ErrorKind.code(error),
|
|
|
|
fields: [error.field]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-04-14 09:49:10 +12:00
|
|
|
defimpl AshGraphql.Error, for: Ash.Error.Changes.InvalidArgument do
|
|
|
|
def to_error(error) do
|
|
|
|
%{
|
|
|
|
message: Exception.message(error),
|
|
|
|
code: Ash.ErrorKind.code(error),
|
|
|
|
fields: [error.field]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
defimpl AshGraphql.Error, for: Ash.Error.Query.InvalidArgument do
|
|
|
|
def to_error(error) do
|
|
|
|
%{
|
|
|
|
message: Exception.message(error),
|
|
|
|
code: Ash.ErrorKind.code(error),
|
|
|
|
fields: [error.field]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-03-16 08:51:17 +13:00
|
|
|
defimpl AshGraphql.Error, for: Ash.Error.Changes.Required do
|
|
|
|
def to_error(error) do
|
|
|
|
%{
|
|
|
|
message: "is required",
|
|
|
|
code: Ash.ErrorKind.code(error),
|
|
|
|
fields: [error.field]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
defimpl AshGraphql.Error, for: Ash.Error.Query.NotFound do
|
|
|
|
def to_error(error) do
|
|
|
|
%{
|
2021-04-17 05:49:51 +12:00
|
|
|
message: "not found",
|
2021-03-16 08:51:17 +13:00
|
|
|
fields: Map.keys(error.primary_key || %{}),
|
|
|
|
code: Ash.ErrorKind.code(error)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
defimpl AshGraphql.Error, for: Ash.Error.Query.Required do
|
|
|
|
def to_error(error) do
|
|
|
|
%{
|
|
|
|
message: "is required",
|
|
|
|
code: Ash.ErrorKind.code(error),
|
|
|
|
fields: [error.field]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|