From 88afb9f34c13c426220f250de8fb8f7f7b92a5db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20Cz=C3=A9m=C3=A1n?= <trabarni@gmail.com> Date: Thu, 8 Feb 2018 03:35:43 +0100 Subject: [PATCH] catch errors --- src/actions/auth.js | 69 ++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 32 deletions(-) diff --git a/src/actions/auth.js b/src/actions/auth.js index 111210a..83463ca 100644 --- a/src/actions/auth.js +++ b/src/actions/auth.js @@ -10,34 +10,37 @@ const axios = ax.create({ export const getUserData = () => ( async (dispatch) => { - const user = await axios.get('/api/v1/profiles/me'); - const { - id, - join_date: joinDate, - nick, - motivation_about: motivationAbout, - motivation_profession: motivationProfession, - motivation_exercise: motivationExercise, - signed, - groups, - } = user.data; - dispatch({ - type: GET_USERDATA, - payload: { - id, joinDate, nick, motivationAbout, motivationProfession, motivationExercise, signed, groups, - }, - }); + try { + const user = await axios.get('/api/v1/profiles/me'); + const { + id, + join_date: joinDate, + nick, + motivation_about: motivationAbout, + motivation_profession: motivationProfession, + motivation_exercise: motivationExercise, + signed, + groups, + } = user.data; + dispatch({ + type: GET_USERDATA, + payload: { + id, joinDate, nick, motivationAbout, motivationProfession, motivationExercise, signed, groups, + }, + }); + } catch (e) {} } ); export const getNews = () => ( async (dispatch) => { - const response= await axios.get('/api/v1/news'); - if(response) { + try { + const response = await axios.get('/api/v1/news'); dispatch({ type: GET_NEWS, payload: response.data, }); + } catch(e) { } } @@ -57,18 +60,20 @@ export const submitRegistration = ({ nick, groups, signed, motivationAbout, motivationProfession, motivationExercise, id, }) => ( async (dispatch) => { - const response = await axios.patch(`/api/v1/profiles/${id}/`, { - nick, - groups, - signed, - motivation_about: motivationAbout, - motivation_profession: motivationProfession, - motivation_exercise: motivationExercise, - }); - if (response.data.id === id) { - alert('Sikeres mentĂŠs!'); - } else { - alert('MentĂŠs nem sikerĂźlt!'); - } + try { + const response = await axios.patch(`/api/v1/profiles/${id}/`, { + nick, + groups, + signed, + motivation_about: motivationAbout, + motivation_profession: motivationProfession, + motivation_exercise: motivationExercise, + }); + if (response.data.id === id) { + alert('Sikeres mentĂŠs!'); + } else { + alert('MentĂŠs nem sikerĂźlt!'); + } + } catch(e) {} } ); -- GitLab