Skip to content

Commit

Permalink
Merge pull request #44 from fc5y/huynhnhan.ngo/fix/ui-popup
Browse files Browse the repository at this point in the history
Fix error popup
  • Loading branch information
hnngo authored Oct 5, 2020
2 parents 2bbe546 + 4907530 commit 07f814a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/app/containers/LoginPage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class LoginPage extends React.Component {
this.props.history.push('/');
}
} else {
const { data, error } = await apiLogin({ username, password });
if (!!error || !data || !data.token) {
const { data } = await apiLogin({ username, password });
if (!data || !data.token) {
this.setState({
showFalsePopup: true,
});
Expand Down
4 changes: 2 additions & 2 deletions src/app/containers/SignupPage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ function SignupPage({ history }) {
setData(sanitizedData);
if (hasBlockingError(getErrors(sanitizedData))) return;
// eslint-disable-next-line no-shadow
signupWithData(sanitizedData).then((data) => {
if (!data || !data.data || !data.data.username) {
signupWithData(sanitizedData).then(({ data, error }) => {
if (!!error || !data || !data.username) {
// TODO: show popup
alert(`Đăng ký không thành công\n\n`);
} else {
Expand Down
30 changes: 19 additions & 11 deletions src/utils/fetchUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,28 @@ import { getFullURL } from './getUrl';
const { ENV } = process.env;

export const get = async (url, options = {}, fullURL = false) => {
const { data, status } = await axios.get(!fullURL ? getFullURL(url, ENV) : url, {
...options,
});
try {
const { data } = await axios.get(!fullURL ? getFullURL(url, ENV) : url, {
...options,
});

return { data, status };
return { data };
} catch (err) {
return { error: (err.response && err.response.data && err.response.data.error) || true };
}
};

export const post = async (url, body, options = {}, fullURL = false) => {
const { data, status } = await axios.post(!fullURL ? getFullURL(url, ENV) : url, body, {
...options,
headers: {
'Content-Type': 'application/json',
},
});
try {
const { data } = await axios.post(!fullURL ? getFullURL(url, ENV) : url, body, {
...options,
headers: {
'Content-Type': 'application/json',
},
});

return { data, status };
return { data };
} catch (err) {
return { error: (err.response && err.response.data && err.response.data.error) || true };
}
};

0 comments on commit 07f814a

Please sign in to comment.