Show a proper error message on creating/updating an event

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2020-10-09 16:07:13 +02:00
parent 9430f1145f
commit 75fc1f125a
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
3 changed files with 14 additions and 3 deletions

View File

@ -588,6 +588,7 @@ export default class EditEvent extends Vue {
} catch (err) { } catch (err) {
this.saving = false; this.saving = false;
console.error(err); console.error(err);
this.handleError(err);
} }
} }
@ -615,7 +616,7 @@ export default class EditEvent extends Vue {
}); });
} catch (err) { } catch (err) {
this.saving = false; this.saving = false;
console.error(err); this.handleError(err);
} }
} }
@ -627,6 +628,16 @@ export default class EditEvent extends Vue {
: this.$i18n.t("The event has been updated")) as string; : this.$i18n.t("The event has been updated")) as string;
} }
private handleError(err: any) {
console.error(err);
if (err.graphQLErrors !== undefined) {
err.graphQLErrors.forEach(({ message }: { message: string }) => {
this.$notifier.error(message);
});
}
}
/** /**
* Put in cache the updated or created event. * Put in cache the updated or created event.
* If the event is not a draft anymore, also put in cache the participation * If the event is not a draft anymore, also put in cache the participation

View File

@ -219,7 +219,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Event do
def update_event( def update_event(
_parent, _parent,
%{event_id: event_id} = args, %{event_id: event_id} = args,
%{context: %{current_user: user}} = _resolution %{context: %{current_user: %User{} = user}} = _resolution
) do ) do
# See https://github.com/absinthe-graphql/absinthe/issues/490 # See https://github.com/absinthe-graphql/absinthe/issues/490
with args <- Map.put(args, :options, args[:options] || %{}), with args <- Map.put(args, :options, args[:options] || %{}),

View File

@ -666,7 +666,7 @@ defmodule Mobilizon.Web.Resolvers.EventTest do
assert hd(json_response(res, 200)["errors"])["message"] == "Event not found" assert hd(json_response(res, 200)["errors"])["message"] == "Event not found"
end end
test "update_event/3 should check the user is an administrator", %{ test "update_event/3 should check the user is the organizer", %{
conn: conn, conn: conn,
actor: _actor, actor: _actor,
user: user user: user