Skip to content

Commit

Permalink
experimental fix for Poison encoder issues
Browse files Browse the repository at this point in the history
  • Loading branch information
whossname committed Feb 4, 2022
1 parent 77148ec commit 4fcdea3
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 37 deletions.
72 changes: 36 additions & 36 deletions lib/poison_endoder_list.ex
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
defimpl Poison.Encoder, for: List do
alias Poison.{Encoder, Pretty}

use Pretty

@compile :inline
@compile :inline_list_funcs

def encode([], _options), do: "[]"

def encode(list, options) do
encode(list, pretty(options), options)
end

def encode([head | string], pretty, options) when is_binary(string) do
encode([head, string], pretty, options)
end

def encode(list, false, options) do
[?[, tl(:lists.foldr(&[?,, Encoder.encode(&1, options) | &2], [], list)), ?]]
end

def encode(list, true, options) do
indent = indent(options)
offset = offset(options) + indent
options = offset(options, offset)

[
"[\n",
tl(:lists.foldr(&[",\n", spaces(offset), Encoder.encode(&1, options) | &2], [], list)),
?\n,
spaces(offset - indent),
?]
]
end
end
# defimpl Poison.Encoder, for: List do
# alias Poison.{Encoder, Pretty}

# use Pretty

# @compile :inline
# @compile :inline_list_funcs

# def encode([], _options), do: "[]"

# def encode(list, options) do
# encode(list, pretty(options), options)
# end

# def encode([head | string], pretty, options) when is_binary(string) do
# encode([head, string], pretty, options)
# end

# def encode(list, false, options) do
# [?[, tl(:lists.foldr(&[?,, Encoder.encode(&1, options) | &2], [], list)), ?]]
# end

# def encode(list, true, options) do
# indent = indent(options)
# offset = offset(options) + indent
# options = offset(options, offset)

# [
# "[\n",
# tl(:lists.foldr(&[",\n", spaces(offset), Encoder.encode(&1, options) | &2], [], list)),
# ?\n,
# spaces(offset - indent),
# ?]
# ]
# end
# end
24 changes: 23 additions & 1 deletion lib/slack_logger_backend/format_helper.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ defmodule SlackLoggerBackend.FormatHelper do
]
|> Enum.reject(&is_nil/1)

message = messge_to_string(detail.message)

{:ok, json} =
%{
attachments: [
%{
fallback: "An #{detail.level} level event has occurred: #{detail.message}",
fallback: "An #{detail.level} level event has occurred: #{message}",
pretext: detail.message,
fields: fields
}
Expand All @@ -49,4 +51,24 @@ defmodule SlackLoggerBackend.FormatHelper do
}
end
end

defp messge_to_string(a) when is_binary(a) do
a
end

defp messge_to_string([a]) do
messge_to_string(a)
end

defp messge_to_string(["\nState: " | _]) do
""
end

defp messge_to_string([a | b]) do
messge_to_string([messge_to_string(a) <> messge_to_string(b)])
end

defp messge_to_string(a) do
inspect(a)
end
end

0 comments on commit 4fcdea3

Please sign in to comment.