mirror of
https://bitbucket.org/wisemapping/wisemapping-frontend.git
synced 2024-11-11 01:43:23 +01:00
Complete error handling.
This commit is contained in:
parent
98ebbaceee
commit
496455d1ea
@ -69,8 +69,6 @@ const RegistrationForm = (props: ServiceProps) => {
|
|||||||
<h1><FormattedMessage id="registration.become" defaultMessage="Become a member of our comunity" /></h1>
|
<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>
|
<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)}>
|
<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="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" />
|
<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"
|
sitekey="6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI"
|
||||||
onChange={setRecaptchaToken} />
|
onChange={setRecaptchaToken} />
|
||||||
</div>
|
</div>
|
||||||
|
<ErrorMessageDialog message={errorMsg} />
|
||||||
|
|
||||||
<p>
|
<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" />
|
<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>
|
</p>
|
||||||
|
|
||||||
<input type="submit" value={intl.formatMessage({ id: "registration.register", defaultMessage: "Register" })} />
|
<input type="submit" value={intl.formatMessage({ id: "registration.register", defaultMessage: "Register" })} />
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
type NewUser =
|
type NewUser = {
|
||||||
{
|
|
||||||
email: string;
|
email: string;
|
||||||
firstname: string;
|
firstname: string;
|
||||||
lastname: string;
|
lastname: string;
|
||||||
password: string;
|
password: string;
|
||||||
recaptcha: string;
|
recaptcha: string;
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
||||||
interface Service {
|
interface Service {
|
||||||
registerNewUser(user: NewUser, onSuccess: () => void, onError: (msg: string) => void): void;
|
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 ...
|
// All was ok, let's sent to success page ...
|
||||||
onSuccess();
|
onSuccess();
|
||||||
}).catch(error => {
|
}).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." })
|
switch (status) {
|
||||||
let msg = 'Unexpected error. Please, try latter';
|
case 401:
|
||||||
if (data != null) {
|
this.authFailed();
|
||||||
msg = Object.values(data.fieldErrors)[0] as string;
|
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);
|
onError(msg);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user