forked from scrollback/scrollback
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandleAuthErrors.es6
62 lines (57 loc) · 1.75 KB
/
handleAuthErrors.es6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* global $ */
"use strict";
const strings = {
EN: {
requiredRoleStr: {
"registered": "signed into scrollback",
"follower": "a follower of this room",
"moderator": "a moderator of this room",
"owner": "an owner of this room"
},
currentRoleTasks: {
"banned": "",
"guest": "signing into scrollback"
},
requiredRoleTasks: {
"follower": "following this room",
"moderator": "asking to be a moderator of this room",
"owner": "asking to be an owner of this room"
},
actionQueryStr: {
"admit": "change someone's role",
"expel": "ban or gag someone",
"back": "enter this room",
"edit": "edit messages in this room",
"join": "join this room",
"part": "leave this room",
"getRooms": "view the room",
"getUsers": "view a user's info",
"room": "save this room",
"user": "save this user account",
"text": "send messages",
"getTexts": "read messages",
"getThreads": "read discussions"
},
currentRoleStr: {
"moderator": "a moderator",
"banned": "banned in this room",
"gagged": "gagged in this room",
"follower": "a follower of this room",
"owner": "the owner of this room"
}
}
};
module.exports = function(error) {
const actionQueryStr = strings.EN.actionQueryStr[error.action],
requiredRoleStr = strings.EN.requiredRoleStr[error.requiredRole],
currentRoleStr = strings.EN.currentRoleStr[error.currentRole],
task = strings.EN.reqestedRoleTasks[error.requiredRole] || strings.EN.currentRoleTasks[error.currentRole];
let errorMessage = [
(requiredRoleStr ? `You should be ${requiredRoleStr} to ${actionQueryStr}.` : ""),
(currentRoleStr ? `You're ${currentRoleStr}.` : ""),
(task ? `Try ${task} first.` : "")
].join(" ");
$("<div>").html(errorMessage).alertbar({
type: "error"
});
};