Skip to content

Commit 453c175

Browse files
committed
Error messages independent from this directive
1 parent 246bb16 commit 453c175

File tree

1 file changed

+18
-51
lines changed

1 file changed

+18
-51
lines changed

angular-awesome-error.js

Lines changed: 18 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
1-
/*
1+
/*
22
* Template for error/success message,
3-
* Show/hide error message when required,
3+
* Show/hide error message when required,
44
* Show/hide success message when required.
55
*/
66

77
(function(window, angular, undefined) {
88

99
'use strict';
10+
1011
angular.module('ngAngularError', ['ng'])
11-
.directive('awesomeError', function () {
12+
.factory('errorsList', function($http) {
13+
/* errors_list.json should contain a map of errors and user-feedback.
14+
* we use, $http to retrieve values from file errors_list.json,
15+
* errorsList factory returns a promise. */
16+
return $http.get('errors_list.json');
17+
})
18+
19+
.directive('awesomeError', function (errorsList) {
1220
return {
1321
restrict: 'E',
1422
replace: true,
@@ -27,55 +35,14 @@
2735
</div> \
2836
</div> \
2937
</div>',
30-
link: function(scope) {
31-
scope.errorMessage = {
32-
"USERNAME_OR_PASSWORD_NOT_CORRECT": "Invalid username or password.",
33-
"USERNAME_OR_PASSWORD_OR_TOKEN_NOT_CORRECT" : "Invalid username or password.",
34-
"MISSING_USERNAME_OR_EMAIL" : "Please, enter a username or email.",
35-
"INVALID_USERNAME_OR_EMAIL" : "Invalid username or email.",
36-
"MISSING_USERNAME" : "Please, enter a username.",
37-
"INVALID_USERNAME" : "Invalid username.",
38-
"USERNAME_NOT_AVAILABLE": "This username is already taken!",
39-
"USERNAME_ALREADY_TAKEN": "This username is already taken!",
40-
"username_REQUIRED": "Please, enter a username.",
41-
"username_INVALID_PATTERN" : "Username should be composed of alphanumerics only and 1 to 15 characters long.",
42-
"USERNAME_UPDATED" : "Username successfully updated.",
43-
44-
"MISSING_PASSWORD" : "Please, enter a password.",
45-
"INVALID_PASSWORD" : "Invalid password.",
46-
"password_REQUIRED" : "Please, enter a password.",
47-
"password_LENGTH_PATTERN" : "Password should be 3 to 15 characters long",
48-
"PASSWORDS_DONT_MATCH" : "Passwords dont match.",
49-
"PASSWORD_UPDATED" : "Password successfully updated.",
50-
51-
"email_INVALID" : "Invalid email.",
52-
"email_REQUIRED" : "Please, enter an email.",
53-
"MISSING_EMAIL" : "Please, enter an email.",
54-
"EMAIL_NOT_AVAILABE" : "This email is already taken!",
55-
"useremail_REQUIRED" : "Please, enter an email.",
56-
"useremail_INVALID" : "Invalid email",
57-
"MAIL_SENT_RESET_PASSWORD" : "Email with password reset instructions has been sent to your email address",
38+
link: function(scope) {
39+
scope.errorMessage = {};
5840

59-
"TOKEN_NOT_VALID" : "Oops, something went wrong. Please, try again later.",
60-
"MISSING_TOKEN" : "Oops, something went wrong. Please, try again later.",
61-
"INVALID_TOKEN" : "Oops, something went wrong. Please, try again later.",
62-
"TOKEN_NOT_CORRECT" : "Oops, something went wrong. Please, try again later.",
63-
"TOKEN_EXPIRED" : "Your session has expired. Please, try to login again.",
64-
65-
"MISSING_GEO" : "We are not able to get your location. Please, try again.",
66-
"INVALID_GEO" : "We are not able to get your location. Please, try again.",
41+
/* fetching data present in 'errors-list.json' file */
42+
errorsList.success(function(data) {
43+
scope.errorMessage = data;
44+
});
6745

68-
"FILE_NOT_VALID" : "File not valid",
69-
"USER_NOT_FOUND" : "This user was not found, we apologise for the inconvenience.",
70-
"SHOUT_NOT_FOUND" : "This message was not found, we apologise for the inconvenience.",
71-
"MISSING_SHOUT" : "Please, enter a message.",
72-
"INVALID_SHOUT" : "Invalid message.",
73-
"INVALID_IN_REPLY_TO" : "Invalid reply message.",
74-
"FEEDBACK_RESPONSE" : "Thank you for your feedback.",
75-
"FEEDBACK_ERROR_RESPONSE" : "Sorry the feedback could not be sent.",
76-
"FEEDBACK_MISSING" : "Please, enter a feedback.",
77-
};
78-
7946
scope.$on('show error', function (args) {
8047
scope.showerr = true;
8148
});
@@ -100,7 +67,7 @@
10067
scope.showMessage = scope.errorMessage[scope.msg];
10168
if (scope.showMessage === "undefined") { scope.showMessage = scope.errorMessage["Undefined"]; }
10269
});
103-
}
70+
}
10471
};
10572
});
10673

0 commit comments

Comments
 (0)