Permalink
Browse files

catch all exits

  • Loading branch information...
Mats Cronqvist authored and richcarl committed Dec 10, 2008
1 parent a02179d commit d4e38f81135b244b136950671398cfc830de1093
Showing with 20 additions and 5 deletions.
  1. +20 −5 src/egeoip.erl
View
@@ -325,18 +325,30 @@ init(FileName) ->
%% @spec handle_call(Msg, From, State) -> term()
%% @doc gen_server callback.
-handle_call({lookup, Address}, _From, State) ->
+handle_call(What,From,State) ->
+ try
+ do_handle_call(What,From,State)
+ catch
+ _:R ->
+ log_error([{handle_call,What},{error,R}]),
+ {reply,{error,R},State}
+ end.
+
+do_handle_call({lookup, Address}, _From, State) ->
Res = lookup(State, Address),
{reply, Res, State};
-handle_call({reload, NewState}, _From, _State) ->
+do_handle_call({reload, NewState}, _From, _State) ->
{reply, ok, NewState};
-handle_call(filename, _From, State) ->
+do_handle_call(filename, _From, State) ->
{reply, State#geoipdb.filename, State}.
%% @spec handle_cast(Msg, State) -> term()
%% @doc gen_server callback.
handle_cast(stop, State) ->
- {stop, normal, State}.
+ {stop, normal, State};
+handle_cast(What, State) ->
+ log_error([{handle_cast, What}]),
+ {noreply, State}.
%% @spec terminate(Reason, State) -> ok
%% @doc gen_server callback.
@@ -351,14 +363,17 @@ code_change(_OldVsn, State, _Extra) ->
%% @spec handle_info(Info, State) -> {noreply, State}
%% @doc gen_server callback.
handle_info(Info, State) ->
- error_logger:info_report([{'INFO', Info}, {'State', State}]),
+ log_error([{handle_info,Info}]),
{noreply, State}.
%% Implementation
get_worker(Address) ->
element(1 + erlang:phash2(Address) band 7,
egeoip_sup:worker_names()).
+log_error(Info) ->
+ error_logger:info_report([?MODULE|Info]).
+
%% @spec new() -> {ok, geoipdb()}
%% @doc Create a new geoipdb database record using the default
%% priv/GeoLiteCity.dat.gz database.

0 comments on commit d4e38f8

Please sign in to comment.