Add human readable version of errors
This commit is contained in:
parent
753a950816
commit
68131a6e2a
5 changed files with 55 additions and 42 deletions
44
js/api.js
44
js/api.js
|
@ -85,31 +85,27 @@ window.textsecure.api = function() {
|
|||
}
|
||||
if (code > 999 || code < 100)
|
||||
code = -1;
|
||||
var e = new Error(code);
|
||||
e.name = "HTTPError";
|
||||
switch (code) {
|
||||
case -1:
|
||||
e.human_error = "Failed to connect to the server, please check your network connection.";
|
||||
break;
|
||||
case 413:
|
||||
e.human_error = "Rate limit exceeded, please try again later.";
|
||||
break;
|
||||
case 403:
|
||||
e.human_error = "Invalid code, please try again.";
|
||||
break;
|
||||
case 417:
|
||||
e.human_error = "Number already registered"; // TODO: This shouldn't be a thing?, but its in the API doc?
|
||||
break;
|
||||
case 401:
|
||||
e.human_error = "Invalid authentication, most likely someone re-registered and invalidated our registration";
|
||||
break;
|
||||
case 404:
|
||||
e.human_error = "Number is not registered with TextSecure..";
|
||||
break;
|
||||
default:
|
||||
e.human_error = "The server rejected our query, please file a bug report.";
|
||||
try {
|
||||
switch (code) {
|
||||
case -1:
|
||||
textsecure.throwHumanError(code, "HTTPError", "Failed to connect to the server, please check your network connection.");
|
||||
case 413:
|
||||
textsecure.throwHumanError(code, "HTTPError", "Rate limit exceeded, please try again later.");
|
||||
case 403:
|
||||
textsecure.throwHumanError(code, "HTTPError", "Invalid code, please try again.");
|
||||
case 417:
|
||||
// TODO: This shouldn't be a thing?, but its in the API doc?
|
||||
textsecure.throwHumanError(code, "HTTPError", "Number already registered.");
|
||||
case 401:
|
||||
textsecure.throwHumanError(code, "HTTPError", "Invalid authentication, most likely someone re-registered and invalidated our registration.");
|
||||
case 404:
|
||||
textsecure.throwHumanError(code, "HTTPError", "Number is not registered with TextSecure.");
|
||||
default:
|
||||
textsecure.throwHumanError(code, "HTTPError", "The server rejected our query, please file a bug report.");
|
||||
}
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue