From f33ff7cbacb204adae9d53ad15829f44c4140525 Mon Sep 17 00:00:00 2001 From: Alexey Lebedeff Date: Fri, 22 Apr 2016 17:33:34 +0300 Subject: Improve error reporting Simplify some return values, improve error messages for eaddrinuse and no_cert. Amended to add tests and simpler code. Also hides the contents of cert and key transport options, if any. --- src/ranch.erl | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/ranch.erl') diff --git a/src/ranch.erl b/src/ranch.erl index 7f751cf..9eb9a47 100644 --- a/src/ranch.erl +++ b/src/ranch.erl @@ -74,9 +74,20 @@ start_listener(Ref, NumAcceptors, Transport, TransOpts, Protocol, ProtoOpts) _ -> ok end, - Res + maybe_started(Res) end. +maybe_started({error, {{shutdown, + {failed_to_start_child, ranch_acceptors_sup, + {listen_error, _, Reason}}}, _}} = Error) -> + start_error(Reason, Error); +maybe_started(Res) -> + Res. + +start_error(E=eaddrinuse, _) -> {error, E}; +start_error(E=no_cert, _) -> {error, E}; +start_error(_, Error) -> Error. + -spec stop_listener(ref()) -> ok | {error, not_found}. stop_listener(Ref) -> case supervisor:terminate_child(ranch_sup, {ranch_listener_sup, Ref}) of -- cgit v1.2.3