Sign up rate limit
This commit is contained in:
parent
7bd1c6e115
commit
fb470eec79
7 changed files with 34 additions and 10 deletions
|
@ -161,9 +161,10 @@ class Api {
|
|||
body: body
|
||||
});
|
||||
if (response.status === 409) {
|
||||
throw new UsernameTakenError(username)
|
||||
}
|
||||
if (response.status !== 200) {
|
||||
throw new UsernameTakenError(username);
|
||||
} else if (response.status === 429) {
|
||||
throw new AccountCreateLimitReachedError();
|
||||
} else if (response.status !== 200) {
|
||||
throw new Error(`Unexpected server response ${response.status}`);
|
||||
}
|
||||
}
|
||||
|
@ -260,5 +261,9 @@ export class UsernameTakenError extends Error {
|
|||
}
|
||||
}
|
||||
|
||||
export class AccountCreateLimitReachedError extends Error {
|
||||
// Nothing
|
||||
}
|
||||
|
||||
const api = new Api();
|
||||
export default api;
|
||||
|
|
|
@ -2,7 +2,7 @@ import * as React from 'react';
|
|||
import TextField from "@mui/material/TextField";
|
||||
import Button from "@mui/material/Button";
|
||||
import Box from "@mui/material/Box";
|
||||
import api, {UsernameTakenError} from "../app/Api";
|
||||
import api, {AccountCreateLimitReachedError, UsernameTakenError} from "../app/Api";
|
||||
import routes from "./routes";
|
||||
import session from "../app/Session";
|
||||
import Typography from "@mui/material/Typography";
|
||||
|
@ -36,6 +36,8 @@ const Signup = () => {
|
|||
console.log(`[Signup] Signup for user ${user.username} failed`, e);
|
||||
if ((e instanceof UsernameTakenError)) {
|
||||
setError(t("Username {{username}} is already taken", { username: e.username }));
|
||||
} else if ((e instanceof AccountCreateLimitReachedError)) {
|
||||
setError(t("Account creation limit reached"));
|
||||
} else if (e.message) {
|
||||
setError(e.message);
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue