我在我的 Phoenix 应用程序中遇到弃用警告:System.stacktrace/0 outside of rescue/catch clauses is deprecated. If you want to support only Elixir v1.7+, you must access __STACKTRACE__ inside a rescue/catch. If you want to support earlier Elixir versions, move System.stacktrace/0 inside a rescue/catch
.
问题是,我正在使用 Rollbax,如他们的文档中所述:Rollbax.report(:error, ArgumentError.exception("oops"), System.stacktrace())
将我正在执行的每个 case 语句包装在 try/rescue 块中感觉有点奇怪。比如这个:
case (SOME_URL |> HTTPoison.get([], [ ssl: [{:versions, [:'tlsv1.2']}] ])) do
{:ok, %HTTPoison.Response{status_code: 200, body: body}} ->
Poison.decode!(body, [keys: :atoms])
{:ok, %HTTPoison.Response{status_code: 404}} ->
Rollbax.report(:error, :not_found, System.stacktrace(), %{reason: "Not found"})
{:ok, %HTTPoison.Response{status_code: 503}} ->
{:error, :ehostunreach}
{:error, %HTTPoison.Error{reason: :ehostunreach}} ->
{:error, :ehostunreach}
{:error, %HTTPoison.Error{reason: :timeout}} ->
Rollbax.report(:error, :timeout, System.stacktrace(), %{reason: :timeout})
{:error, %HTTPoison.Error{reason: reason}} ->
Rollbax.report(:error, :unknown, System.stacktrace(), %{reason: reason})
{:error, reason}
end
我不确定如何在一次救援中获得这些不同的报告......写这个的正确方法是什么?