Skip to content

Commit

Permalink
The "error" property should be a string not a boolean
Browse files Browse the repository at this point in the history
The "error" property of the Login class object carries information about which type of login error
has been thrown, which is later used to build the message key to retrieve the corresponding
translated message to show to users.

Therefore it should remain a string, and not simply a boolean.
  • Loading branch information
diegodlh committed Sep 10, 2024
1 parent 5c9797b commit 69ee60a
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/cita/wikidata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1065,12 +1065,12 @@ export default class {
class Login {
cancelled: any;
anonymous: any;
error: boolean;
error: string;
username: any;
password: any;
save?: boolean;
constructor() {
this.error = false;
this.error = "";
}

get credentials() {
Expand All @@ -1082,23 +1082,23 @@ class Login {
}

onError(error: Error) {
this.error = false;
this.error = "";
if (error.name == "badtoken") {
if (this.anonymous) {
// See https://github.com/maxlath/wikibase-edit/issues/63
// fix: not sure if this should be bool or string?
this.error = true; //'unsupportedAnonymous';
this.error = 'unsupportedAnonymous';
} else {
debug("Unexpected login error", error);
this.error = true; // = 'unknown';
this.error = 'unknown';
}
} else if (error.message.split(":")[0] == "failed to login") {
const reason = error.message.split(":")[1].trim();
if (reason === "invalid username/password") {
this.error = true; // = 'wrongCredentials';
this.error = 'wrongCredentials';
} else {
debug("Unexpected login error", error);
this.error = true; // = 'unknown';
this.error = 'unknown';
}
}
// I don't want permissiondenied errors to be treated as
Expand All @@ -1111,7 +1111,7 @@ class Login {
}

onSuccess() {
this.error = false;
this.error = "";
if (!this.anonymous && this.save) {
debug("Saving credentials to be implemented");
}
Expand Down

0 comments on commit 69ee60a

Please sign in to comment.