From 0dddc17b9d7da5152407f10cf7621905a4f689cd Mon Sep 17 00:00:00 2001 From: Christopher Date: Wed, 1 Apr 2020 19:26:06 -0500 Subject: [PATCH] handle all errors --- lib/router/session.ex | 37 ++++++++++++++++++++----------------- mix.exs | 4 ++-- mix.lock | 4 ++-- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/lib/router/session.ex b/lib/router/session.ex index 9dac0fe..bcb8d7e 100644 --- a/lib/router/session.ex +++ b/lib/router/session.ex @@ -257,7 +257,7 @@ defmodule Wampex.Router.Session do realm: realm, authorization_module: am, peer: peer, - subscribe: %Subscribe{request_id: ri, options: opts, topic: topic}, + subscribe: %Subscribe{request_id: rid, options: opts, topic: topic}, db: db } = data } = sl @@ -267,13 +267,14 @@ defmodule Wampex.Router.Session do true -> id = RealmSession.get_id() wc = RealmSession.subscribe(db, realm, topic, {id, {self(), Node.self()}}, opts) - send_to_peer(Broker.subscribed(%Subscribed{request_id: ri, subscription_id: id}), tt, t) + send_to_peer(Broker.subscribed(%Subscribed{request_id: rid, subscription_id: id}), tt, t) {%SL{sl | data: %Sess{data | subscriptions: [{id, topic, wc} | subs]}}, [{:next_event, :internal, :transition}]} false -> - {%SL{sl | data: %Sess{data | error: "wamp.error.not_authorized"}}, [{:next_event, :internal, :transition}]} + send_to_peer(Broker.subscribe_error(%Error{request_id: rid, error: "wamp.error.not_authorized"}), tt, t) + {sl, [{:next_event, :internal, :transition}]} end {:ok, data, actions} @@ -307,17 +308,16 @@ defmodule Wampex.Router.Session do _, @publish, %SL{ - data: - %Sess{ - proxy: proxy, - realm: realm, - transport: tt, - transport_pid: t, - db: db, - authorization_module: am, - peer: peer, - publish: %Publish{request_id: rid, options: opts, topic: topic, arg_list: arg_l, arg_kw: arg_kw} - } = data + data: %Sess{ + proxy: proxy, + realm: realm, + transport: tt, + transport_pid: t, + db: db, + authorization_module: am, + peer: peer, + publish: %Publish{request_id: rid, options: opts, topic: topic, arg_list: arg_l, arg_kw: arg_kw} + } } = sl ) do {data, actions} = @@ -351,7 +351,8 @@ defmodule Wampex.Router.Session do {sl, [{:next_event, :internal, :transition}]} false -> - {%SL{sl | data: %Sess{data | error: "wamp.error.not_authorized"}}, [{:next_event, :internal, :transition}]} + send_to_peer(Broker.publish_error(%Error{request_id: rid, error: "wamp.error.not_authorized"}), tt, t) + {sl, [{:next_event, :internal, :transition}]} end {:ok, data, actions} @@ -411,7 +412,8 @@ defmodule Wampex.Router.Session do [{:next_event, :internal, :transition}]} false -> - {%SL{sl | data: %Sess{data | error: "wamp.error.not_authorized"}}, [{:next_event, :internal, :transition}]} + send_to_peer(Dealer.register_error(%Error{request_id: rid, error: "wamp.error.not_authorized"}), tt, t) + {sl, [{:next_event, :internal, :transition}]} end {:ok, data, actions} @@ -495,7 +497,8 @@ defmodule Wampex.Router.Session do end false -> - {%SL{sl | data: %Sess{data | error: "wamp.error.not_authorized"}}, [{:next_event, :internal, :transition}]} + send_to_peer(Dealer.call_error(%Error{request_id: call_id, error: "wamp.error.not_authorized"}), tt, t) + {sl, [{:next_event, :internal, :transition}]} end {:ok, data, actions} diff --git a/mix.exs b/mix.exs index 6d1acaa..b86375a 100644 --- a/mix.exs +++ b/mix.exs @@ -49,10 +49,10 @@ defmodule Wampex.Router.MixProject do {:msgpack, "~> 0.7.0"}, {:plug_cowboy, "~> 2.1"}, {:states_language, "~> 0.2"}, - {:wampex, git: "https://gitlab.com/entropealabs/wampex.git", tag: "c7bb690087f9f14832dcd4f222a8bd92154af78d"}, + {:wampex, git: "https://gitlab.com/entropealabs/wampex.git", tag: "61d834a784f5f14ec90508cf7556a5ebaec113c3"}, {:wampex_client, git: "https://gitlab.com/entropealabs/wampex_client.git", - tag: "40b0f3765cd9c2930d576b203e0e7ab3679f7129", + tag: "909a70ec0475472d7fe2f567a851b9fcdf0f6ded", only: [:dev, :test]} ] end diff --git a/mix.lock b/mix.lock index 0dbacfa..aae6e72 100644 --- a/mix.lock +++ b/mix.lock @@ -36,8 +36,8 @@ "states_language": {:hex, :states_language, "0.2.8", "f9dfd3c0bd9a9d7bda25ef315f2d90944cd6b2022a7f3c403deb1d4ec451825e", [:mix], [{:elixpath, "~> 0.1.0", [hex: :elixpath, repo: "hexpm", optional: false]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:json_xema, "~> 0.4.0", [hex: :json_xema, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:xema, "~> 0.11.0", [hex: :xema, repo: "hexpm", optional: false]}], "hexpm", "a5231691e7cb37fe32dc7de54c2dc86d1d60e84c4f0379f3246e55be2a85ec78"}, "telemetry": {:hex, :telemetry, "0.4.1", "ae2718484892448a24470e6aa341bc847c3277bfb8d4e9289f7474d752c09c7f", [:rebar3], [], "hexpm", "4738382e36a0a9a2b6e25d67c960e40e1a2c95560b9f936d8e29de8cd858480f"}, "unicode_util_compat": {:hex, :unicode_util_compat, "0.4.1", "d869e4c68901dd9531385bb0c8c40444ebf624e60b6962d95952775cac5e90cd", [:rebar3], [], "hexpm", "1d1848c40487cdb0b30e8ed975e34e025860c02e419cb615d255849f3427439d"}, - "wampex": {:git, "https://gitlab.com/entropealabs/wampex.git", "c7bb690087f9f14832dcd4f222a8bd92154af78d", [tag: "c7bb690087f9f14832dcd4f222a8bd92154af78d"]}, - "wampex_client": {:git, "https://gitlab.com/entropealabs/wampex_client.git", "40b0f3765cd9c2930d576b203e0e7ab3679f7129", [tag: "40b0f3765cd9c2930d576b203e0e7ab3679f7129"]}, + "wampex": {:git, "https://gitlab.com/entropealabs/wampex.git", "61d834a784f5f14ec90508cf7556a5ebaec113c3", [tag: "61d834a784f5f14ec90508cf7556a5ebaec113c3"]}, + "wampex_client": {:git, "https://gitlab.com/entropealabs/wampex_client.git", "909a70ec0475472d7fe2f567a851b9fcdf0f6ded", [tag: "909a70ec0475472d7fe2f567a851b9fcdf0f6ded"]}, "websockex": {:hex, :websockex, "0.4.2", "9a3b7dc25655517ecd3f8ff7109a77fce94956096b942836cdcfbc7c86603ecc", [:mix], [], "hexpm", "803cd76e91544b56f0e655e36790be797fa6436db9224f7c303db9b9df2a3df4"}, "xema": {:hex, :xema, "0.11.0", "7b5118418633cffc27092110d02d4faeea938149dd3f6c64299e41e747067e80", [:mix], [{:conv_case, "~> 0.2.2", [hex: :conv_case, repo: "hexpm", optional: false]}, {:decimal, "~> 1.7", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "51491c9a953d65069d4b30aa2f70bc45ff99fd1bc3345bc72ce4e644d01ea14e"}, } -- 2.45.3