definig success and error callbacks for every private axios request

This commit is contained in:
Delucse
2020-12-11 14:35:24 +01:00
parent 1821ac4e40
commit 4f002d8694
10 changed files with 179 additions and 78 deletions
+12 -4
View File
@@ -95,14 +95,22 @@ class SaveProject extends Component {
if(this.state.projectType === 'gallery'){
body.description = this.state.description;
}
axios.post(`${process.env.REACT_APP_BLOCKLY_API}/${this.state.projectType}`, body)
.then(res => {
const config = {
success: res => {
var project = res.data[this.state.projectType];
this.props.history.push(`/${this.state.projectType}/${project._id}`);
})
.catch(err => {
},
error: err => {
this.setState({ snackbar: true, key: Date.now(), message: `Fehler beim Speichern des ${this.state.projectType === 'gallery' ? 'Galerie-':''}Projektes. Versuche es noch einmal.`, type: 'error' });
window.scrollTo(0, 0);
}
};
axios.post(`${process.env.REACT_APP_BLOCKLY_API}/${this.state.projectType}`, body, config)
.then(res => {
res.config.success(res);
})
.catch(err => {
err.config.error(err);
});
}