Add API to handle server warnings
Closed this issue · 0 comments
whatyouhide commented
Since native protocol v4, C* supports sending warnings in the responses that come from the server.
We should add an API that lets users of Xandra handle those warnings. The first proposal is an option to pass to Xandra.start_link/1
, :warning_handler
. It can be a function with two arguments or a {module, function, additional_args}
tuple.
The function passed to this option would be called as:
case options[:warning_handler] do
fun when is_function(fun, 2) -> fun.(query, warnings)
{mod, fun, args} -> apply(mod, fun, [query, warnings | args])
end
Xandra should ship with a default implementation that uses Logger.warn/1
. Basically, the default for :warning_handler
would be something like
fn query, warnings ->
Enum.each(warnings, fn warning ->
Logger.warn("Server warninng for query #{prettify(query)}: #{warning}")
end)
end