Skip to content

Commit

Permalink
feat(webapp): sign-up: improve handling of response status 429
Browse files Browse the repository at this point in the history
  • Loading branch information
peterthomassen committed Jan 21, 2022
1 parent 39bfd16 commit 8847361
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions webapp/src/views/SignUp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,23 @@
async getCaptcha(focus = false) {
this.captchaWorking = true;
this.captchaSolution = "";
this.captcha_errors = [];
try {
this.captcha = (await HTTP.post('captcha/', {kind: this.captcha_kind})).data;
if(focus) {
this.$refs.captchaField.focus()
} catch (error) {
if (error.response && error.response.status == 429) {
this.captcha = null;
let retryAfter = parseInt(error.response.headers['retry-after']);
this.captcha_errors = [`Too many attempts. Please try again in ${retryAfter} seconds.`];
setTimeout(() => this.captcha || this.getCaptcha(), 1000 * retryAfter);
} else {
throw error;
}
} finally {
this.captchaWorking = false;
if(focus) {
this.$refs.captchaField.focus()
}
}
},
async initialFocus() {
Expand Down Expand Up @@ -286,9 +296,12 @@
});
this.$router.push({name: 'welcome', params: domain !== '' ? {domain: domain} : {}});
} catch (error) {
if (error.response) {
// status is not 2xx
if (error.response.status < 500 && typeof error.response.data === 'object') {
if (error.response) { // status is not 2xx
if (error.response && error.response.status == 429) {
let retryAfter = parseInt(error.response.headers['retry-after']);
this.errors = [`Too many attempts. Please try again in ${retryAfter} seconds.`];
setTimeout(() => this.errors = [], 1000 * retryAfter);
} else if (error.response.status < 500 && typeof error.response.data === 'object') {
// 3xx or 4xx
let extracted = false;
this.getCaptcha(true);
Expand Down

0 comments on commit 8847361

Please sign in to comment.