mirror of
https://github.com/OkaeriPoland/okaeri-timings.git
synced 2026-01-18 03:28:20 +01:00
Expose backend errors to the user with modal
This commit is contained in:
@@ -58,10 +58,43 @@
|
|||||||
</MDBRow>
|
</MDBRow>
|
||||||
</MDBContainer>
|
</MDBContainer>
|
||||||
|
|
||||||
|
<MDBModal id="errorModal" tabindex="-1" labelledby="errorModalLabel" v-model="errorModal">
|
||||||
|
<MDBModalHeader>
|
||||||
|
<MDBModalTitle id="errorModalLabel">
|
||||||
|
<font-awesome-icon icon="exclamation-triangle"/>
|
||||||
|
Error
|
||||||
|
</MDBModalTitle>
|
||||||
|
</MDBModalHeader>
|
||||||
|
<MDBModalBody>
|
||||||
|
{{ errorContent }}
|
||||||
|
</MDBModalBody>
|
||||||
|
<MDBModalFooter>
|
||||||
|
<MDBBtn color="primary" @click="errorModal = false">Close</MDBBtn>
|
||||||
|
</MDBModalFooter>
|
||||||
|
</MDBModal>
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import {MDBCard, MDBCardBody, MDBCardText, MDBCardTitle, MDBCol, MDBContainer, MDBFile, MDBNavbar, MDBNavbarItem, MDBNavbarNav, MDBRow} from 'mdb-vue-ui-kit';
|
import {
|
||||||
|
MDBBtn,
|
||||||
|
MDBCard,
|
||||||
|
MDBCardBody,
|
||||||
|
MDBCardText,
|
||||||
|
MDBCardTitle,
|
||||||
|
MDBCol,
|
||||||
|
MDBContainer,
|
||||||
|
MDBFile,
|
||||||
|
MDBModal,
|
||||||
|
MDBModalBody,
|
||||||
|
MDBModalFooter,
|
||||||
|
MDBModalHeader,
|
||||||
|
MDBModalTitle,
|
||||||
|
MDBNavbar,
|
||||||
|
MDBNavbarItem,
|
||||||
|
MDBNavbarNav,
|
||||||
|
MDBRow
|
||||||
|
} from 'mdb-vue-ui-kit';
|
||||||
import ReportSummary from "@/components/report/summary/ReportSummary";
|
import ReportSummary from "@/components/report/summary/ReportSummary";
|
||||||
import ReportHistoryProcMeminfo from "@/components/report/history/ReportHistoryProcMeminfo";
|
import ReportHistoryProcMeminfo from "@/components/report/history/ReportHistoryProcMeminfo";
|
||||||
import ReportHistoryProcStat from "@/components/report/history/ReportHistoryProcStat";
|
import ReportHistoryProcStat from "@/components/report/history/ReportHistoryProcStat";
|
||||||
@@ -84,7 +117,13 @@ export default {
|
|||||||
MDBFile,
|
MDBFile,
|
||||||
MDBRow,
|
MDBRow,
|
||||||
MDBCol,
|
MDBCol,
|
||||||
MDBCardText
|
MDBCardText,
|
||||||
|
MDBModal,
|
||||||
|
MDBModalBody,
|
||||||
|
MDBModalFooter,
|
||||||
|
MDBModalHeader,
|
||||||
|
MDBModalTitle,
|
||||||
|
MDBBtn
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
msg: String
|
msg: String
|
||||||
@@ -94,9 +133,22 @@ export default {
|
|||||||
let formData = new FormData();
|
let formData = new FormData();
|
||||||
formData.append('file', value[0]);
|
formData.append('file', value[0]);
|
||||||
this.report = await this.axios.post('/v1/parse', formData, {headers: {'Content-Type': 'multipart/form-data'}})
|
this.report = await this.axios.post('/v1/parse', formData, {headers: {'Content-Type': 'multipart/form-data'}})
|
||||||
.then((response) => response.data)
|
.then((response) => {
|
||||||
.catch((error) => console.log(error));
|
console.log(`Report parsing took ${response.data.stats.parseTime}`);
|
||||||
console.log(`Report parsing took ${this.report.stats.parseTime}`);
|
return response.data;
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
if (error.response) {
|
||||||
|
this.showError(error.response.data.error);
|
||||||
|
} else {
|
||||||
|
this.showError(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
errorModal: function (value) {
|
||||||
|
if (!value) {
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
setup: function () {
|
setup: function () {
|
||||||
@@ -108,7 +160,21 @@ export default {
|
|||||||
return {
|
return {
|
||||||
files: ref([]),
|
files: ref([]),
|
||||||
report: ref(),
|
report: ref(),
|
||||||
|
errorModal: ref(false),
|
||||||
|
errorContent: undefined
|
||||||
};
|
};
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
showError(error) {
|
||||||
|
if (typeof (error) === 'string') {
|
||||||
|
this.errorContent = error;
|
||||||
|
} else if (error.message === 'Network Error') {
|
||||||
|
this.errorContent = 'API server cannot be reached. Please check your network connection.'
|
||||||
|
} else {
|
||||||
|
this.errorContent = `Unknown error: ${error.message || JSON.stringify(error)}`
|
||||||
|
}
|
||||||
|
this.errorModal = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user