Skip to content

Commit

Permalink
show errors comming from backend
Browse files Browse the repository at this point in the history
  • Loading branch information
m-salehi-v committed Feb 4, 2021
1 parent b365c42 commit 4490323
Show file tree
Hide file tree
Showing 17 changed files with 37 additions and 43 deletions.
11 changes: 5 additions & 6 deletions src/components/CLI/CLI.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ const CLI = props => {
description: 'log out',
usage : 'logout' ,
fn : function () {
console.log(token);
dispatch(actions.logoutUser(token));
}
}
Expand All @@ -147,7 +146,7 @@ const CLI = props => {

useEffect (() =>{
if(error!=null) {
terminal.current.pushToStdout(error.message);
terminal.current.pushToStdout(error);
}
},[error])

Expand Down Expand Up @@ -176,7 +175,7 @@ const CLI = props => {

useEffect(() => {
if(questionsErr != null){
terminal.current.pushToStdout(questionsErr.message);
terminal.current.pushToStdout(questionsErr);
}
},[questionsErr])

Expand All @@ -197,7 +196,7 @@ const CLI = props => {

useEffect(() => {
if(jokesErr != null){
terminal.current.pushToStdout(jokesErr.message);
terminal.current.pushToStdout(jokesErr);
}
},[jokesErr])

Expand Down Expand Up @@ -241,7 +240,7 @@ const CLI = props => {

useEffect(() => {
if(upFileErr != null){
terminal.current.pushToStdout(upFileErr.message);
terminal.current.pushToStdout(upFileErr);
}
}, [upFileErr])

Expand All @@ -264,7 +263,7 @@ const CLI = props => {

useEffect (()=>{
if(scoresError){
terminal.pushToStdout(scoresError.message);
terminal.pushToStdout(scoresError);
}
}, [scoresError])

Expand Down
6 changes: 1 addition & 5 deletions src/components/GUI/GUI.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const GUI = props => {
if (questionsLoading) {
content = <Spinner animation="border" />
} else if (questionsErr) {
content = <Alert variant="danger">{questionsErr.message}</Alert>
content = <Alert variant="danger">{questionsErr}</Alert>
} else if (questions) {
content = <GUIQuestions
questions={questions}
Expand All @@ -47,12 +47,8 @@ const GUI = props => {

const mapStateToProps = (state) => {
return {
upFileSuc: state.fileUploader.success,
upFileErr: state.fileUploader.error,
token: state.userAuth.token,
username: state.userAuth.username,
questions: state.userQuestions.questions,
questionsSuccess: state.userQuestions.success,
questionsErr: state.userQuestions.error,
questionsLoading: state.userQuestions.loading,
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/GUIQuestions/GUIQuestions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ const GUIQuestions = ({ questions, qClickHandler, selectedQIndex,
تست کیس منحصر به خود را دانلود کنید
</Button>
: testCaseError ?
<Alert variant="danger">{testCaseError.message}</Alert>
<Alert variant="danger">{testCaseError}</Alert>
: null}
<SubmitTitle>ارسال پاسخ</SubmitTitle>
{(success && showSuccess) && <Alert variant="success">Question submitted successfully</Alert>}
{(error && showError) && <Alert variant="danger">{error.message}</Alert>}
{(error && showError) && <Alert variant="danger">{error}</Alert>}
<Form style={{ direction: 'rtl', textAlign: 'right' }}
onSubmit={onSubmitHandler}
>
Expand Down
2 changes: 1 addition & 1 deletion src/components/QuestionForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const QuestionForm = (props) => {
<Form style={{ padding: '20px' }}
onSubmit={onSubmitHandler}
>
{error && <Alert variant="danger">{error.message}</Alert>}
{error && <Alert variant="danger">{error}</Alert>}
{formElements.map((element, index) => (
<Form.Group key={index}>
<Form.Label>{element.label}</Form.Label>
Expand Down
2 changes: 1 addition & 1 deletion src/components/UserLoginForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const UserLoginForm = ({ loading, error }) => {
<Card.Title className="text-center" style={{ fontSize: '26px' }}>{isSignUp ? 'Register' : 'Login'}</Card.Title>
{errorToShow != null ?
<Alert variant={'danger'}>
{errorToShow.message}
{errorToShow}
</Alert> : null}
{form}
</Card.Body>
Expand Down
2 changes: 1 addition & 1 deletion src/containers/AdminLogin/AdminLogin.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const AdminLogin = props => {
<Card.Title className="text-center" style={{ fontSize: '26px' }}>Login</Card.Title>
{error != null ?
<Alert variant={'danger'}>
{error.message}
{error}
</Alert> : null}
<Form
onSubmit={signinSubmitHandler}
Expand Down
2 changes: 1 addition & 1 deletion src/containers/Questions/Questions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const QAdminPanel = (props) => {
</h1>
<AddNewBtn color="#2da829" style={{ fontWeight: 'bold' }} onClick={onAddClick}>Add New </AddNewBtn>
</Header>
{error && <Alert variant="danger">{error.message}</Alert>}
{error && <Alert variant="danger">{error}</Alert>}
{loading ? <Spinner animation="border" /> : null}
{dataList}
</ListContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const UserAdminList = (props) => {
</h1>
<AddNewBtn color="#2da829" style={{ fontWeight: 'bold' }} onClick={onAddClick}>Add New </AddNewBtn>
</Header>
{error && <Alert variant="danger">{error.message}</Alert>}
{error && <Alert variant="danger">{error}</Alert>}
{loading ? <Spinner animation="border" /> : null}
{dataList}
</ListContainer>
Expand Down
4 changes: 2 additions & 2 deletions src/store/actions/adminAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const authSuperAdmin = (userData, adminType) => {
dispatch(authSuccess(response.data.token, username));
})
.catch(error => {
dispatch(authFail(error));
dispatch(authFail(error.response && error.response.data.error ? error.response.data.error : error.message));
});
}
}
Expand All @@ -57,7 +57,7 @@ export const logoutSuperAdmin = (token, adminType) => {
});
dispatch(logoutSuccess());
} catch (error) {
console.log(error);
console.log(error.response && error.response.data.error ? error.response.data.error : error.message);
}
}
}
2 changes: 1 addition & 1 deletion src/store/actions/fetchJokes.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const fetchJokes = (arg) => {
dispatch(jokesFetchSuccess(jokes));
}
catch (error) {
dispatch(jokesFetchFailure(error))
dispatch(jokesFetchFailure(error.response && error.response.data.error ? error.response.data.error : error.message))
}
}
sendReq();
Expand Down
2 changes: 1 addition & 1 deletion src/store/actions/fetchUserQuestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const fetchUserQuestions = (token) => {
dispatch(questionsFetchSuccess(response.data));
}
catch (error) {
dispatch(questionsFetchFailure(error))
dispatch(questionsFetchFailure(error.response && error.response.data.error ? error.response.data.error : error.message))
}
}
sendReq();
Expand Down
4 changes: 3 additions & 1 deletion src/store/actions/fileUploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export const uploadFile = (data, token) => {
.then(res => {
dispatch(fileUploadSuccess(data));
})
.catch(err => { dispatch(fileUploadFailure(err)) })
.catch(error => {
dispatch(fileUploadFailure(error.response && error.response.data.error ? error.response.data.error : error.message))
})
}
}
3 changes: 1 addition & 2 deletions src/store/actions/getTestCase.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ export const getTestCase = (id ,name, token, dirDownload) => {
dispatch(testCaseGetSuccess(testCase));
}
catch (error) {
dispatch(testCaseGetFail(error));
console.log(error);
dispatch(testCaseGetFail(error.response && error.response.data.error ? error.response.data.error : error.message));
}
}
sendReq();
Expand Down
9 changes: 4 additions & 5 deletions src/store/actions/questions.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const getQuestions = (token) => dispatch => {
dispatch(fetchQestionsSuccess(response.data));
})
.catch(error => {
dispatch(fetchQestionsFail(error));
dispatch(fetchQestionsFail(error.response && error.response.data.error ? error.response.data.error : error.message));
});
}

Expand All @@ -64,8 +64,7 @@ export const addQuestion = (token, data) => dispatch => {
})
.then(response => {dispatch(createQuestionSuccess())})
.catch(error => {
console.log(error);
dispatch(createQuestionFail(error));
dispatch(createQuestionFail(error.response && error.response.data.error ? error.response.data.error : error.message));
});
}

Expand All @@ -78,7 +77,7 @@ export const deleteQuestion = (token, id) => dispatch => {
})
.then(response => {dispatch(getQuestions(token))})
.catch(error => {
dispatch(fetchQestionsFail(error));
dispatch(fetchQestionsFail(error.response && error.response.data.error ? error.response.data.error : error.message));
});

}
Expand All @@ -92,7 +91,7 @@ export const editQuestion = (token, data, id) => dispatch => {
})
.then(response => {dispatch(editQuestionSuccess())})
.catch(error => {
dispatch(editQuestionFail(error));
dispatch(editQuestionFail(error.response && error.response.data.error ? error.response.data.error : error.message));
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/store/actions/scoreBoard.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const getScoreBoard = (scores) => {
dispatch(scoreBoardGetSuccess(scores));
}
catch (error) {
dispatch(scoreBoardGetFail(error))
dispatch(scoreBoardGetFail(error.response && error.response.data.error ? error.response.data.error : error.message))
}
}
sendReq();
Expand Down
17 changes: 8 additions & 9 deletions src/store/actions/user-admin-CRUD.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const getUsers = (token) => dispatch => {
dispatch(userSuccess(response.data, 'user'));
})
.catch(error => {
dispatch(userFail(error));
dispatch(userFail(error.response && error.response.data.error ? error.response.data.error : error.message));
});
}

Expand All @@ -50,7 +50,7 @@ export const getQAdmins = (token) => dispatch => {
dispatch(userSuccess(response.data, 'QAdmin'));
})
.catch(error => {
dispatch(userFail(error));
dispatch(userFail(error.response && error.response.data.error ? error.response.data.error : error.message));
});
}

Expand All @@ -64,8 +64,7 @@ export const addUser = (token,userData) => dispatch => {
})
.then(response => {dispatch(getUsers(token))})
.catch(error => {
console.log(error);
dispatch(userFail(error));
dispatch(userFail(error.response && error.response.data.error ? error.response.data.error : error.message));
});
}

Expand All @@ -78,7 +77,7 @@ export const addQAdmin = (token,userData) => dispatch => {
})
.then(response => {dispatch(getQAdmins(token))})
.catch(error => {
dispatch(userFail(error));
dispatch(userFail(error.response && error.response.data.error ? error.response.data.error : error.message));
});
}

Expand All @@ -91,7 +90,7 @@ export const deleteUser = (token,studentNumber) => dispatch => {
})
.then(response => {dispatch(getUsers(token))})
.catch(error => {
dispatch(userFail(error));
dispatch(userFail(error.response && error.response.data.error ? error.response.data.error : error.message));
});

}
Expand All @@ -104,7 +103,7 @@ export const deleteQAdmin = (token,username) => dispatch => {
})
.then(response => {dispatch(getQAdmins(token))})
.catch(error => {
dispatch(userFail(error));
dispatch(userFail(error.response && error.response.data.error ? error.response.data.error : error.message));
});
}

Expand All @@ -117,7 +116,7 @@ export const editUser = (token,userData, studentNumber) => dispatch => {
})
.then(response => {dispatch(getUsers(token))})
.catch(error => {
dispatch(userFail(error));
dispatch(userFail(error.response && error.response.data.error ? error.response.data.error : error.message));
});
}

Expand All @@ -131,7 +130,7 @@ export const editQAdmin = (token,adminData, username) => dispatch => {
})
.then(response => {dispatch(getQAdmins(token))})
.catch(error => {
dispatch(userFail(error));
dispatch(userFail(error.response && error.response.data.error ? error.response.data.error : error.message));
});
}

Expand Down
6 changes: 3 additions & 3 deletions src/store/actions/userAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const authUser = (userData) => {
dispatch(authSuccess(response.data.token, response.data.user.studentNumber));
})
.catch(error => {
dispatch(authFail(error));
dispatch(authFail(error.response && error.response.data.error ? error.response.data.error : error.message));
});
}
}
Expand All @@ -53,7 +53,7 @@ export const userSignUp = (userData) =>{
})
.catch(error => {
console.log(error.response);
dispatch(authFail(error.response));
dispatch(authFail(error.response && error.response.data.error ? error.response.data.error : error.message));
});
}
}
Expand All @@ -68,7 +68,7 @@ export const logoutUser = (token) => {
});
dispatch(logoutSuccess());
} catch (error) {
console.log(error);
console.log(error.response && error.response.data.error ? error.response.data.error : error.message);
}
}
}

0 comments on commit 4490323

Please sign in to comment.