aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/client.erl44
1 files changed, 16 insertions, 28 deletions
diff --git a/server/client.erl b/server/client.erl
index 333df4a..cb6504e 100644
--- a/server/client.erl
+++ b/server/client.erl
@@ -14,43 +14,31 @@ start(Node) ->
{error, {unknown_error, Why}}
end.
+execute(Client, F) ->
+ %% execute F() with error handling
+ %% (sends error message on exception)
+ try F() of
+ Result ->
+ Client ! {ok, Result}
+ catch
+ _: Why ->
+ Client ! {error, Why}
+ end.
+
loop(Client) ->
+ %% mainloop for client modul in server
receive
list ->
- try media:all() of
- Result ->
- Client ! {ok, Result}
- catch
- _: Why ->
- Client ! {error, Why}
- end;
+ execute(Client, fun() -> media:all() end);
get_votes ->
- try media:getVotes(Client) of
- Result ->
- Client ! {ok, Result}
- catch
- _: Why ->
- Client ! {error, Why}
- end;
+ execute(Client, fun() -> media:getVotes(Client) end);
{vote, Artist, Title} ->
- try media:vote(Artist, Title) of
- Result ->
- Client ! {ok, Result}
- catch
- _: Why ->
- Client ! {error, Why}
- end;
+ execute(Client, fun() -> media:vote(Artist, Title) end);
{devote, Artist, Title} ->
- try media:devote(Artist, Title) of
- Result ->
- Client ! {ok, Result}
- catch
- _: Why ->
- Client ! {error, Why}
- end;
+ execute(Client, fun() -> media:devote(Artist, Title) end);
Cmd ->
Client ! {error, {unknown_command, Cmd}}