Complete error handling.

This commit is contained in:
Paulo Gustavo Veiga 2020-12-06 15:56:30 -08:00
parent 98ebbaceee
commit 496455d1ea
2 changed files with 33 additions and 18 deletions

View File

@ -69,8 +69,6 @@ const RegistrationForm = (props: ServiceProps) => {
<h1><FormattedMessage id="registration.become" defaultMessage="Become a member of our comunity" /></h1>
<p><FormattedMessage id="registration.signup" defaultMessage="Signing up is free and just take a moment " /></p>
<ErrorMessageDialog message={errorMsg} />
<form action="/" method="POST" onSubmit={e => handleSubmit(e)}>
<input type="email" name="email" onChange={e => setEmail(e.target.value)} placeholder={intl.formatMessage({ id: "registration.email", defaultMessage: "Email" })} required={true} autoComplete="email" />
<input type="text" name="firstname" onChange={e => setFirstname(e.target.value)} placeholder={intl.formatMessage({ id: "registration.firstname", defaultMessage: "First Name" })} required={true} autoComplete="given-name" />
@ -82,10 +80,11 @@ const RegistrationForm = (props: ServiceProps) => {
sitekey="6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI"
onChange={setRecaptchaToken} />
</div>
<ErrorMessageDialog message={errorMsg} />
<p>
<FormattedMessage id="registration.termandconditions" defaultMessage="Terms of Service: Please check the WiseMapping Account information you've entered above, and review the Terms of Service here. By clicking on 'Register' below you are agreeing to the Terms of Service above and the Privacy Policy" />
</p>
<input type="submit" value={intl.formatMessage({ id: "registration.register", defaultMessage: "Register" })} />
</form>
</div>

View File

@ -1,13 +1,11 @@
import axios from 'axios'
type NewUser =
{
type NewUser = {
email: string;
firstname: string;
lastname: string;
password: string;
recaptcha: string;
}
}
interface Service {
registerNewUser(user: NewUser, onSuccess: () => void, onError: (msg: string) => void): void;
@ -30,12 +28,30 @@ class RestService implements Service {
// All was ok, let's sent to success page ...
onSuccess();
}).catch(error => {
const data = error.response;
const response = error.response;
let msg = '';
if (response) {
const status: number = response.status;
const data = response.data;
// let errorMsg = intl.formatMessage({ id: "registration.unexpected", defaultMessage: "Unexpected error. Please, try latter." })
let msg = 'Unexpected error. Please, try latter';
if (data != null) {
msg = Object.values(data.fieldErrors)[0] as string;
switch (status) {
case 401:
this.authFailed();
break;
default:
console.log(data);
// Is a server error ?
if (!data.fieldErrors) {
msg = response.statusText;
} else if (data) {
const fieldsError = data.fieldErrors;
msg = Object.values(fieldsError)[0] as string;
}
}
} else {
// Network related problem ...
msg = 'Unexpected error. Please, try latter';
}
onError(msg);
});