mirror of
https://github.com/notherealmarco/WASAPhoto.git
synced 2025-03-14 06:06:15 +01:00
Fix error when there is no network connection
This commit is contained in:
parent
8613a5780f
commit
92522876b7
4 changed files with 40 additions and 34 deletions
|
@ -26,20 +26,20 @@ export default {
|
|||
// Leave response as is
|
||||
return response;
|
||||
}, error => {
|
||||
if (error.response != undefined) {
|
||||
if (error.response.status != 0) {
|
||||
// If the response is 401, redirect to /login
|
||||
if (error.response.status === 401) {
|
||||
this.$router.push({ path: '/login' })
|
||||
return
|
||||
return;
|
||||
}
|
||||
|
||||
// Show the error message from the server in a modal
|
||||
this.showModal("Error " + error.response.status, error.response.data['status'])
|
||||
return
|
||||
return;
|
||||
}
|
||||
// Show the error message from axios in a modal
|
||||
this.showModal("Error", error.toString());
|
||||
return error;
|
||||
return;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ import getCurrentSession from "./authentication";
|
|||
|
||||
const instance = axios.create({
|
||||
baseURL: __API_URL__,
|
||||
timeout: 1000 * 20
|
||||
timeout: 1000 * 60
|
||||
});
|
||||
|
||||
//axios.interceptors.request.use(function (config) {
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
export default {
|
||||
data: function() {
|
||||
return {
|
||||
errormsg: null,
|
||||
loading: false,
|
||||
stream_data: [],
|
||||
data_ended: false,
|
||||
start_idx: 0,
|
||||
limit: 1,
|
||||
loadingError: false,
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
@ -23,16 +23,18 @@ export default {
|
|||
},
|
||||
async loadContent() {
|
||||
this.loading = true;
|
||||
this.errormsg = null;
|
||||
try {
|
||||
let response = await this.$axios.get("/stream?start_index=" + this.start_idx + "&limit=" + this.limit);
|
||||
if (response.data.length == 0) this.data_ended = true;
|
||||
else this.stream_data = this.stream_data.concat(response.data);
|
||||
this.loading = false;
|
||||
} catch (e) {
|
||||
// todo: handle better
|
||||
this.errormsg = e.toString();
|
||||
|
||||
let response = await this.$axios.get("/stream?start_index=" + this.start_idx + "&limit=" + this.limit);
|
||||
|
||||
if (response == null) {
|
||||
this.loading = false
|
||||
this.loadingError = true
|
||||
return
|
||||
}
|
||||
|
||||
if (response.data.length == 0) this.data_ended = true;
|
||||
else this.stream_data = this.stream_data.concat(response.data);
|
||||
this.loading = false;
|
||||
},
|
||||
scroll () {
|
||||
window.onscroll = () => {
|
||||
|
@ -58,8 +60,6 @@ export default {
|
|||
<div class="col-xl-6 col-lg-9">
|
||||
<h3 class="card-title border-bottom mb-4 pb-2 text-center">Your daily WASAStream!</h3>
|
||||
|
||||
<ErrorMsg v-if="errormsg" :msg="errormsg"></ErrorMsg>
|
||||
|
||||
<div v-if="(stream_data.length == 0)" class="alert alert-secondary text-center" role="alert">
|
||||
There's nothing here 😢
|
||||
<br />Why don't you start following somebody? 👻
|
||||
|
@ -80,6 +80,7 @@ export default {
|
|||
</div>
|
||||
|
||||
<LoadingSpinner :loading="loading" /><br />
|
||||
<button v-if="loadingError" @click="refresh" class="btn btn-secondary w-100 py-3">Retry</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -3,8 +3,10 @@ export default {
|
|||
data: function () {
|
||||
return {
|
||||
requestedProfile: this.$route.params.user_id,
|
||||
errormsg: null,
|
||||
|
||||
loading: false,
|
||||
loadingError: false,
|
||||
|
||||
stream_data: [],
|
||||
data_ended: false,
|
||||
start_idx: 0,
|
||||
|
@ -27,26 +29,30 @@ export default {
|
|||
},
|
||||
|
||||
async getMainData() {
|
||||
try {
|
||||
let response = await this.$axios.get("/users/" + this.requestedProfile);
|
||||
this.user_data = response.data;
|
||||
} catch (e) {
|
||||
this.errormsg = e.toString();
|
||||
let response = await this.$axios.get("/users/" + this.requestedProfile);
|
||||
|
||||
if (response == null) {
|
||||
this.loading = false
|
||||
this.loadingError = true
|
||||
return
|
||||
}
|
||||
this.user_data = response.data;
|
||||
},
|
||||
|
||||
async loadContent() {
|
||||
this.loading = true;
|
||||
this.errormsg = null;
|
||||
try {
|
||||
let response = await this.$axios.get("/users/" + this.requestedProfile + "/photos" + "?start_index=" + this.start_idx + "&limit=" + this.limit);
|
||||
if (response.data.length == 0) this.data_ended = true;
|
||||
else this.stream_data = this.stream_data.concat(response.data);
|
||||
this.loading = false;
|
||||
} catch (e) {
|
||||
// todo: handle better
|
||||
this.errormsg = e.toString();
|
||||
|
||||
let response = await this.$axios.get("/users/" + this.requestedProfile + "/photos" + "?start_index=" + this.start_idx + "&limit=" + this.limit);
|
||||
|
||||
if (response == null) {
|
||||
// do something
|
||||
return
|
||||
}
|
||||
|
||||
if (response.data.length == 0) this.data_ended = true;
|
||||
else this.stream_data = this.stream_data.concat(response.data);
|
||||
this.loading = false;
|
||||
|
||||
},
|
||||
scroll() {
|
||||
window.onscroll = () => {
|
||||
|
@ -79,8 +85,6 @@ export default {
|
|||
<div class="row justify-content-md-center">
|
||||
<div class="col-xl-6 col-lg-9">
|
||||
|
||||
<ErrorMsg v-if="errormsg" :msg="errormsg"></ErrorMsg>
|
||||
|
||||
<UserCard :user_id="requestedProfile" :name="user_data['name']" :followed="user_data['followed']"
|
||||
:banned="user_data['banned']" :my_id="this.$currentSession" :show_new_post="true"
|
||||
@updateInfo="getMainData" @updatePosts="refresh" />
|
||||
|
@ -110,6 +114,7 @@ export default {
|
|||
</div>
|
||||
|
||||
<LoadingSpinner :loading="loading" /><br />
|
||||
<button v-if="loadingError" @click="refresh" class="btn btn-secondary w-100 py-3">Retry</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue