web/satellite: error handling for login/signup rate limit exceeding

related jira issue:
https://storjlabs.atlassian.net/browse/USR-767

Change-Id: I4b4f27435323234ce6803c06a8c5b004f91873bf
This commit is contained in:
VitaliiShpital 2020-05-14 16:05:10 +03:00 committed by Vitalii Shpital
parent 7d00b3c792
commit f0619c6db7
2 changed files with 21 additions and 4 deletions

View File

@ -2,6 +2,7 @@
// See LICENSE for copying information.
import { ErrorEmailUsed } from '@/api/errors/ErrorEmailUsed';
import { ErrorTooManyRequests } from '@/api/errors/ErrorTooManyRequests';
import { ErrorUnauthorized } from '@/api/errors/ErrorUnauthorized';
import { UpdatedUser, User } from '@/types/users';
import { HttpClient } from '@/utils/httpClient';
@ -49,11 +50,14 @@ export class AuthHttpApi {
return await response.json();
}
if (response.status === 401) {
throw new Error('your email or password was incorrect, please try again');
switch (response.status) {
case 401:
throw new ErrorUnauthorized('Your email or password was incorrect, please try again');
case 429:
throw new ErrorTooManyRequests('You\'ve exceeded limit of attempts, try again in 5 minutes');
default:
throw new Error('Can not receive authentication token');
}
throw new Error('can not receive authentication token');
}
/**
@ -211,6 +215,8 @@ export class AuthHttpApi {
throw new ErrorUnauthorized('We are unable to create your account. This is an invite-only alpha, please join our waitlist to receive an invitation');
case 409:
throw new ErrorEmailUsed('This email is already in use, try another');
case 429:
throw new ErrorTooManyRequests('You\'ve exceeded limit of attempts, try again in 5 minutes');
default:
throw new Error('Can not register user');
}

View File

@ -0,0 +1,11 @@
// Copyright (C) 2020 Storj Labs, Inc.
// See LICENSE for copying information.
/**
* ErrorTooManyRequests is a custom error type for performing 'too many requests' operations.
*/
export class ErrorTooManyRequests extends Error {
public constructor(message: string = 'Too many requests') {
super(message);
}
}